【问题标题】:Setting TaskbarItemInfo via WPF Style or Trigger通过 WPF 样式或触发器设置 TaskbarItemInfo
【发布时间】:2012-03-14 02:54:13
【问题描述】:

WPF 4 包含一个“TaskbarItemInfo”Freezable 类,该类将附加属性添加到允许更改各种 Windows 7 任务栏项目的窗口。

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

例如:

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

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

看起来好像没有通过样式设置附加属性。我通过样式设置附加属性的语法不正确,还是我遗漏了其他内容?

【问题讨论】:

    标签: wpf windows-7 dependency-properties


    【解决方案1】:

    TaskbarItemInfo 不继承自 FrameworkElement,因此您无需在 DataTrigger 中设置 Style 属性。

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

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

    然后一个简单的转换器可以返回适用于您的触发器属性的TaskbarItemProgressState

    【讨论】:

    • 这个状态会随着属性的变化而更新吗?
    猜你喜欢
    • 2019-07-22
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 2012-06-02
    • 1970-01-01
    相关资源
    最近更新 更多