Search code examples
c#wpftelerikdatatriggerradwindow

DataTrigger for IconTemplate in RadWindow


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?


Solution

  • 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.