我在设置Silverlight
DataGrid
时遇到了一些问题,我确实有使用WPF
样式的经验,并且在WPF中设置了我DataGrid
的样式让我满意,但现在我我尝试将Silverlight
DataGrid
设置为与WPF
相同,但似乎Silverlight styles
没有Style.Triggers
。如何将WPF DataGrid
转换为Silverlight
?
下面的样式:
<Style TargetType="DataGrid" x:Key="DataGridStyle">
<!-- Make the border and grid lines a little less imposing -->
<Setter Property="BorderBrush" Value="#DDDDDD" />
<Setter Property="HorizontalGridLinesBrush" Value="#DDDDDD" />
<Setter Property="VerticalGridLinesBrush" Value="#DDDDDD" />
<Setter Property="AlternationCount" Value="2"/>
<Setter Property="AutoGenerateColumns" Value="False"/>
<Setter Property="RowStyle">
<Setter.Value>
<Style TargetType="DataGridRow">
<Style.Triggers>
<!-- Highlight a grid row as the mouse passes over -->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, AncestorLevel=1}, Path=IsReadOnly}" Value="True">
<Setter Property="Background" Value="WhiteSmoke" />
</DataTrigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="WhiteSmoke"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
</Style.Triggers>
</Style>
</Setter.Value>
</Setter>
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Style.Triggers>
<!-- Highlight selected rows -->
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FF41B1E1" />
<Setter Property="BorderBrush" Value="#FF41B1E1" />
<Setter Property="Foreground" Value="Black" />
</Trigger>
</Style.Triggers>
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" />
<EventSetter Event="PreviewTextInput" Handler="DataGridCell_PreviewTextInput" />
<!-- Add some padding around the contents of a cell -->
<Setter Property="Padding" Value="4,3,4,3" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Border Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
我注意到Silverlight
使用了VisualStateManager
,但似乎无法使用它开始运行。
我唯一真正关心的是我想要将文字颜色(Foreground
)更改为黑色,因为当前Background
为白色,然后更改颜色({{ 1}})所选单元格。
谢谢