根据属性值设置图标?

时间:2017-11-26 11:25:55

标签: wpf xaml mahapps.metro

我需要根据属性Value设置一个特定的图标,例如我有一个名为ConnectionStatus的属性,它是一个布尔值,现在在DataTrigger中我做了以下内容:

<simpleChildWindow:ChildWindow.Style>
    <Style TargetType="simpleChildWindow:ChildWindow">
        <Style.Triggers>
            <DataTrigger Binding="{Binding ConnectionStatus}" Value="True">
                <Setter Property="Icon" Value="???" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</simpleChildWindow:ChildWindow.Style>

我不知道如何传递这些内容:

<simpleChildWindow:ChildWindow.Icon>
    <materialDesign:PackIcon Kind="ServerOff" 
                             Width="22" 
                             Height="22"
                             HorizontalAlignment="Center"
                             VerticalAlignment="Center"/>
</simpleChildWindow:ChildWindow.Icon>

在setter的价值内,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

如何将PackIcon声明为静态资源。然后使用资源键引用它?

<simpleChildWindow:ChildWindow.Resources>
    <materialDesign:PackIcon x:Key=“icon1” Kind="ServerOff" 
                         Width="22" 
                         Height="22"
                         HorizontalAlignment="Center"
                         VerticalAlignment="Center"/>
</simpleChildWindow:ChildWindow.Resources>

And

<Setter Property="Icon" Value="{Binding Source={StaticResource icon1}}" />