【发布时间】:2012-03-20 23:51:17
【问题描述】:
我有一个用户控件,上面有一个按钮。 UserControl 有一个名为 IsNew 的 DependencyProperty。这是一个布尔值,如果控件中正在编辑的对象是新创建的并且尚未写入数据库,则该值设置为 true。否则为假。
我有一个当前显示“保存”的按钮。我被要求更改按钮,如果该行是新的,它会显示“插入”。我现在有下面的 XAML 按钮:
<Button Background="{DynamicResource ButtonBackground}"
Click="SaveButton_Click"
Content="Save"
FontSize="20"
FontWeight="Bold"
Foreground="{DynamicResource ButtonForeground}"
Height="60"
IsEnabled="{Binding Path=IsDirty, RelativeSource={RelativeSource AncestorType={x:Type cs:Editor}}}"
Margin="5"
Name="SaveButton"
TabIndex="7"
Visibility="{Binding Path=CanModify, Converter={StaticResource BoolToVisibility}}">
<Button.Triggers>
<Trigger Property="Editor.IsNew" Value="True">
<Setter Property="Button.Content" Value="Insert" />
</Trigger>
<Trigger Property="Editor.IsNew>
<Setter Property="Button.Content" Value="Save" />
</Trigger>
</Button.Triggers>
</Button>
我在运行时遇到异常,其内部异常如下:
Triggers collection members must be of type EventTrigger.
如何让它工作?我可以在代码隐藏中轻松做到这一点,但我想在 XAML 中做到这一点。
谢谢
托尼
【问题讨论】: