4

A follow up to this question, why is {x:Null} no longer a valid option for Setter.Value?

Put this code in a resource dictionary in your UWP app:

<Style x:Key="MyList"
        TargetType="ListView">
    <Setter Property="Transitions" 
            Value="{x:Null}"/>
</Style>

And use it in any ListView:

<ListView Style="{StaticResource MyList}"/>

Your app will crash. A nasty crash as well, the kind that takes down the app without breaking properly in your debugger.

Also, the designer complains with a Catastrophic failure:

enter image description here

I know that setting values to {x:Null} is valid. If you set the <ListView Transitions="{x:Null}"/> directly, then it works fine... as expected.

So... what happened with style setters? ... Care to explain, Microsoft? Is there at least an alternate method?

Community
  • 1
  • 1
Laith
  • 6,071
  • 1
  • 33
  • 60

2 Answers2

3

It is really a weird behavior and overall because as you explained setting directly to null works and with the style does not. The only alternative I found is just set a clear transitioncollection:

<Page.Resources>
<Style x:Key="MyList" TargetType="ListView">
    <Setter Property="Transitions" >
        <Setter.Value>
            <TransitionCollection></TransitionCollection>
        </Setter.Value>
    </Setter>
    <Setter Property="DataContext" Value="{x:Null}"/>
</Style>

I set the example of the DataContext that can be set to null, it says the same error but compiles and works.

I know it is not the best solution but it is a workaround to have a clear transitioncollection.

Juan Pablo Garcia Coello
  • 3,192
  • 1
  • 23
  • 33
  • It looks like this is the only way. Hopefully MS will fix this in the future. Thanks Juan. – Laith Oct 10 '15 at 23:03
0

in this quiestion null-value-inside-a-template i've answered and you can find more answers

<Color x:Key="BgNull"></Color>
<Style x:Key="L2" TargetType="TextBox">
  <Setter Property="Background" Value="{StaticResource BgNull}"/>
</Style>
Community
  • 1
  • 1