通过Style&&& amp;&和在XAML中触发

时间:2012-02-19 07:33:39

标签: wpf xaml binding triggers styles

我的代码就像那样

<Window x:Class="SolutionName.ClassName"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="300" Width="300" WindowStartupLocation="CenterOwner">
<Window.Style>
    <Style TargetType="Window">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=ItemKind}" Value="SomeKind">
                <Setter Property="Title" Value="SomeTitle"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=ItemKind}" Value="SomeKind2">
                <Setter Property="Title" Value="SomeTitle"/>
            </DataTrigger>

我想根据viewmodel中实现的属性 ItemKind 更改窗口标题(设置为datacontext)。上面的代码不起作用,我真的很困惑,因为找不到任何错误。

1 个答案:

答案 0 :(得分:2)

代码似乎很好并且在我的最后工作。您是否在ViewModel类中实现了INotifyPropertyChanged。您需要实现它,以便在ViewModel类中传播属性值的任何更改,以反映您的UI。

How to: Implement Property Change Notification

相关问题