<Set> not working in <Case>

Somehow the <set>-element isn’t working inside a case element in my sample:

<Switch ux:Name="mSwitch">
    <Clicked>
        <Match Value="{mSwitch.Value}">
            <Case Bool="true">
                <Set mText.Value="on" />
            </Case>
            <Case Bool="false" >
                <Set mText.Value="off" />
            </Case>
        </Match> 
    </Clicked>
</Switch>
<Text ux:Name="mText" >
    off
</Text>

If I move the <set>-lines outside the <case> it works

Error message:

'Set' does not have an attached property called 'mText.Value', nor does it support implicit set-properties

Try using

<Text ux:Name="mText" Value="off" />

and for set use:

<Set Target="mText" Value="on" />
<Set Target="mText" Value="off" />

That should work, and use that pattern across it makes everything easier

Changed it to:

<Switch ux:Name="mSwitch">
    <Clicked>
        <Set Target="mDebug.Value" Value="{Property mText.Value}" />
        <Match Value="{Property mSwitch.Value}">
            <Case Bool="true">
                <Set Target="mText.Value" Value="on" />
            </Case>
            <Case Bool="false" >
                <Set Target="mText.Value" Value="off" />
            </Case>
        </Match> 
    </Clicked>
</Switch>
<Text ux:Name="mText" Value="off" />

But now getting problems because <Match> doesn’t seem to accept bools.

Try moving the Match outside of the Clicked trigger. It will not be rooted unless the clicked trigger is active, which it will only be for an instant in this case.

Something like this:

<Switch ux:Name="mSwitch">
    <Clicked>
        <Set Target="mDebug.Value" Value="{Property mText.Value}" />
    </Clicked>
    <Match Value="{Property mSwitch.Value}">
        <Case Bool="true">
            <Set Target="mText.Value" Value="on" />
        </Case>
        <Case Bool="false" >
            <Set Target="mText.Value" Value="off" />
        </Case>
    </Match> 
</Switch>
<Text ux:Name="mText" Value="off" />

Still getting Error: `Cannot bind property 'Value' (object) to 'Value' (bool), the types don't match. If you created the property 'Value', consider changing its type to 'object'.

Can you show more code can’t tell what is mDebug

Complete Code:

<App>
    <StackPanel Alignment="Center">
        <Switch ux:Name="mSwitch">
            <Clicked>
                <Set Target="mDebug.Value" Value="{Property mText.Value}" />

            </Clicked>
            <Match Value="{Property mSwitch.Value}">
                    <Case Bool="true">
                        <Set Target="mText.Value" Value="on" />
                    </Case>
                    <Case Bool="false" >
                        <Set Target="mText.Value" Value="off" />
                    </Case>
                </Match> 
        </Switch>
        <Text ux:Name="mText" Value="off" />
        <Text ux:Name="mDebug" Value="{Property mText.Value}" />
    </StackPanel>
</App>

mDebug is only a text element for debug purposes

So it seems like this is not possible not sure if a bug or intended:

<App>
    <StackPanel Alignment="Center">
        <Switch ux:Name="mSwitch" />
        <Text ux:Name="mText" Value="{Property mSwitch.Value}" />
    </StackPanel>
</App>

But here’s what you want:

<App>
    <StackPanel Alignment="Center">
        <Switch ux:Name="mSwitch" />
        <WhileTrue Value="{Property mSwitch.Value}">
            <Change Target="mText.Value" Value="on" />
        </WhileTrue>
        <Text ux:Name="mText" Value="off" />
    </StackPanel>
</App>

It works now!

Thanks :slight_smile:

I don’t think its still a bug

What I don’t understand is why it doesn’t display the boolean text true or false with:

<App>
    <StackPanel Alignment="Center">
        <Switch ux:Name="mSwitch" />
        <Text ux:Name="mText" Value="{Property mSwitch.Value}" />
    </StackPanel>
</App>

It’s because of the types but it should convert the boolean to string

{Property x} is a 2-way binding thus it can’t perform any conversions. I believe we have a feature request to provide a 1-way bindable version that will allow type conversions.