我正在尝试做一些类似的事情:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Button>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Content"
Value="No mouse over" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Content">
<Setter.Value>
<CheckBox Content="Mouse is over" />
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
</Window>
但是,我得到了一个运行时XamlParseException,其中包含以下消息:
无法将'System.Windows.Controls.CheckBox‘类型的内容添加到'System.Object’类型的对象。对象'System.Windows.Controls.CheckBox‘处出错
实际上,我正在尝试根据外部条件为按钮的内容绘制不同的图标。所以我实际上是在尝试使用DataTrigger,但上面的例子简化了问题。有什么想法吗?
https://stackoverflow.com/questions/1050737
复制相似问题