Silverlight数据网格样式MVVM

时间:2014-06-02 06:25:50

标签: silverlight styling

我在设置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}})所选单元格。

谢谢

0 个答案:

没有答案