Question

Can anyone tell me why the following doesn't work, but the one after it does? Notice the Value= syntax versus the explicit usage on the latter. I don't understand the difference.

<Style.Triggers>
    <DataTrigger Binding="{Binding ItemType}" Value="{x:Type log:FranchiseAiring}">
        <Setter Property="Template" Value="{StaticResource FranchiseRowStyle}" />
    </DataTrigger>
</Style.Triggers>

Above throws an exception, below works fine:

<Style.Triggers>
<DataTrigger Binding="{Binding ItemType}">
    <DataTrigger.Value>
        <x:Type Type="{x:Type log:FranchiseAiring}" />
    </DataTrigger.Value>
    <Setter Property="Template" Value="{StaticResource FranchiseRowStyle}" />
</DataTrigger>

Exception: Must specify both Binding and Value for DataTrigger. Error at object 'System.Windows.DataTrigger' in markup file ';component/ResourceDictionaries/LogStyles.xaml' Line 14 Position 15.

Stack Trace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri,

Was it helpful?

Solution

It it probably caused by the bug Anurag linked to, but you should be aware that the two examples you used are not precisely identical from a XAML point of view.

If you convert this to element property syntax

Value="{x:Type whatever}"

what you get is:

<DataTrigger.Value>
  <x:Type TypeName="whatever">
</DataTrigger.Value>

What you wrote in your question actually corresponds to

Value="{x:Type Type={x:Type whatever}}"

Because of the semantics of TypeExtension, both ought to produce the same value in every situation I can think of. But for other purposes they may be different, and they may tickle different bugs in WPF.

Because of this, it is possible that Value="{x:Type Type={x:Type log:FranchiseAiring}}" might work for you. You may want to try it and find out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top