在我的代码隐藏构造函数中,我将数据上下文设置为匿名类型:
Class MainWindow
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.DataContext = New With {
.theTrigger = "trigger value"
}
End Sub
End Class
在我的xaml文件中,Button
应根据上面的theTrigger
属性将其内容更改为自定义值。仅按钮TextBlock
更改内容。这是xaml:
<StackPanel>
<Button>
Init
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding theTrigger}" Value="trigger value">
<Setter Property="Content" Value="Triggered!" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<TextBox Text="{Binding theTrigger}" />
</StackPanel>