我的DataGrid的行中有两个按钮。
案例1.我点击了编辑按钮,此时应该发生2件事......
案例2.我点击了保存按钮:
案例3.当我点击取消按钮时:
案例4.当我点击删除按钮时:
我已经成功实现了案例1的第一点。这是XAML:
<Style TargetType="{x:Type Button}" x:Key="EditSaveButton">
<Setter Property="Margin" Value="3" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Background" Value="{StaticResource NoramlEditButtonBorderBrush}" />
<Setter Property="Content" Value="{StaticResource EditButtonPathData}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="Border" Background="{StaticResource NoramlEditButtonBorderBrush}" Padding="5,2" SnapsToDevicePixels="true" CornerRadius="3">
<Border.Effect>
<DropShadowEffect ShadowDepth="{StaticResource NoramlEditButtonShadowDepth}"
Color="{StaticResource NoramlEditButtonShadowColor}"
BlurRadius="{StaticResource NoramlEditButtonBlurRadius}" />
</Border.Effect>
<Path x:Name="buttonSymbol" Data="{TemplateBinding Content}" Stretch="Uniform" Fill="#FFFFFFFF" Height="24" Width="24" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{Binding Background,RelativeSource={RelativeSource TemplatedParent}}" />
<Setter TargetName="Border" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0"
Color="{Binding Background.Brush,RelativeSource={RelativeSource TemplatedParent}}"
BlurRadius="10" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Border" Property="Background" Value="{StaticResource PressedEditButtonBorderBrush}" />
<Setter TargetName="Border" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="{StaticResource PressedEditButtonShadowDepth}"
Color="{StaticResource PressedEditButtonShadowColor}"
BlurRadius="{StaticResource PressedEditButtonBlurRadius}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledEditButtonBorderBrush}" />
<Setter TargetName="Border" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="{StaticResource DisabledEditButtonShadowDepth}"
Color="{StaticResource DisabledEditButtonShadowColor}"
BlurRadius="{StaticResource DisabledEditButtonBlurRadius}" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsEditing,RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="true">
<Setter Property="Content" Value="{StaticResource SaveButtonPathData}" />
<Setter Property="Background" Value="{StaticResource NoramlSaveButtonBorderBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
如果有人给出了案例1第二点的答案,那么我将尝试完成其他案例。
感谢.............
答案 0 :(得分:1)
我认为你接近这个的方式是增加额外的复杂性。您实际上需要四个按钮而不是两个按钮,但在任何时候只能看到两个按钮。
我将使用布尔值IsInEdit并使用它来绑定按钮的可见性(用于编辑/删除的可见性转换器,用于保存/取消的反向可见性转换器)
保存或取消IsInEdit = false
以及修改IsInEdit = true