locked
How to set a default value on a DataTemplate in a Grid Application? RRS feed

  • Question

  • When I was using WPF, I can set a dataTemplate doing this:

    <Image Stretch="UniformToFill">
         <Image.Style>
             <Style TargetType="Image">
                 <Setter Property="Source" Value="{Binding Image}"/>
                 <Style.Triggers>
                     <DataTrigger Binding="{Binding Image}" Value="{x:Null}">
                         <Setter Property="Source" Value="Images/Default.png"/>
                     </DataTrigger>
                 </Style.Triggers>
             </Style>
        </Image.Style>
    </Image>

    And doing this in a Grid Application does not work, it throws me: The attachable property triggers was not found in style. How can I solve it?

    Thanks a lot!

    Sunday, April 8, 2012 4:44 AM

Answers

  • Oscar,

    There are not DataTriggers in XAML for Metro Style applications.

    You can use value converter to coalesce null into default image which can be set as ConverterParameter if you want to set it from XAML.

    - ngm

    Sunday, April 8, 2012 5:50 AM