通过WPF样式或触发器设置TaskbarItemInfo

WPF 4包含一个“TaskbarItemInfo”Freezable类,它向Window添加一个附加属性,允许更改各种
Windows 7任务栏项.

特别是,我正在尝试在窗口的tasbar图标上设置进度信息.我想使用DataTrigger执行此操作,但它似乎不起作用.我尝试使用一个简单的样式设置器,但这也不起作用 – 只有直接属性赋值或直接属性绑定才有效.

例如:

<Window.Style>
    <Style>
        <Setter Property="TaskbarItemInfo.ProgressState" Value="Indeterminate" />
    </Style>
</Window.Style>

<Window.TaskbarItemInfo>
    <TaskbarItemInfo />
</Window.TaskbarItemInfo>

似乎附加属性没有通过样式设置.我通过样式设置附加属性的语法不正确,还是我错过了其他内容?

最佳答案 TaskbarItemInfo不从FrameworkElement继承,因此您无需在DataTrigger中设置Style属性.

为什么不将TaskbarItemInfo的ProgressState绑定到您想要在DataTrigger中使用的属性,然后使用ValueConverter将其转换为相关的TaskbarItemProgressState.

<Window.TaskbarItemInfo>
    <TaskbarItemInfo ProgressState="{Binding YourProperty, Mode=OneWay, Converter={StaticResource ProgressStateConverter}}" />
</Window.TaskbarItemInfo>   

然后,一个简单的转换器可以返回任何TaskbarItemProgressState应用于您的触发器属性.

点赞