【问题标题】:Bind Path in ResourceDictionary's dependant on VM propertyResourceDictionary 中的绑定路径依赖于 VM 属性
【发布时间】:2015-06-03 05:23:04
【问题描述】:

我创建了一个 ResourceDictionary,它定义了一组在按钮 ControlTemplate 的 ContentPresenter 中使用的 System.Windows.Shapes.Path

我想根据 ViewModel 属性更改其中一个路径。如果true 按钮使用ResourceDictionary 中的一个路径,如果false 使用不同的路径。

目前我只是在 xaml 中引用一个 StaticResource 来直接指向我想要显示的路径。

最好的方法是什么?

【问题讨论】:

    标签: c# wpf mvvm-light resourcedictionary


    【解决方案1】:

    您必须通过引用资源字典中的元素来修改样式中按钮的内容模板。

    类似这样的: <Button.Style> <Style TargetType="Button"> <Setter Property="ContentTemplate" Value="{StaticResource cp2}"></Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="ContentTemplate" Value="{StaticResource cp1}"></Setter> </Trigger> </Style.Triggers> </Style> </Button.Style>

    我已使用鼠标悬停属性作为更改内容模板的触发器。 你可以用DataTrigger代替Trigger

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-13
      • 2016-01-22
      • 2012-11-08
      • 2012-08-01
      • 2017-12-24
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多