DataTrigger for IconTemplate in RadWindow

141 views Asked by At

I have a WPF application and I use Telerik. I'm trying to set the Icon Template so that it has a default value and only on a certain condition will it bind the image source:

<telerik:RadWindow.Resources>
    <Style x:Key="CustomIconStyle" TargetType="Image">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsConditionMet, ElementName=MyWindow, UpdateSourceTrigger=PropertyChanged}" Value="True">
                <Setter Property="Source" Value="{Binding Path=IconImageSource, ElementName=MyWindow, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</telerik:RadWindow.Resources>
<telerik:RadWindow.IconTemplate>
    <DataTemplate>
        <Image Style="{StaticResource CustomIconStyle}" Source="/MyAssembly;Component/Resources/myIcon.ico" Height="16" Margin="0,0,5,0"/>
    </DataTemplate>
</telerik:RadWindow.IconTemplate>

For some reason it always show the default icon. I would also like to mention that I did implement the property changed - and I copied the same style just to a control inside the window and not in the template and it worked - so the problem isn't with the property changed Any ideas?

2

There are 2 answers

0
Maya S On BEST ANSWER

So the problem was that once the RadWindow was loaded it didn't change the Icon. The solution:

<telerik:RadWindow.IconTemplate>
    <DataTemplate>
        <Image  Height="16" Margin="0,0,5,0">
            <Image.Style>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Source" Value="/MyAssembly;Component/Resources/myIcon.ico" />
                    <Style.Triggers>
                        <DataTrigger Value="True" Binding="{Binding Path=IsConditionMet, ElementName=MyWindow}">
                            <Setter Property="Source" Value="{Binding Path=IconImageSource, ElementName=MyWindow}"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Image.Style>
        </Image>
    </DataTemplate>
</telerik:RadWindow.IconTemplate>

But the trick is to give the correct value of IsConditionMet in the windows constructor before the load. Thanks for the help everyone.

0
Amine On

You can use Triggers like that :

<telerik:RadWindow.Resources>
        <Style TargetType="Image" x:Key="Style1">
            <Setter Property="Source" Value="default.ico"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding MyCondition}" Value="true">
                    <Setter Property="Source" Value="custom.ico"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </telerik:RadWindow.Resources>
    <telerik:RadWindow.IconTemplate>
        <DataTemplate>
            <Image Style="{StaticResource Style1}" Height="16" Margin="0,0,5,0"/>
        </DataTemplate>
    </telerik:RadWindow.IconTemplate>