由RowStyle覆盖的WPF DataGrid SelectionUnit属性

时间:2017-02-25 18:39:49

标签: c# wpf xaml

我有一个DataGrid,其SelectionUnit属性设置为" FullRow"。这是按预期工作的,但我需要根据某些条件更改行背景颜色,并且突然将执行时间中的SelectionUnit更改为" Cell"。这是DataGrid的XAML代码:

<DataGrid SelectedItem="{Binding order, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  IsSynchronizedWithCurrentItem="True" SelectionMode="Single" SelectionUnit="FullRow" ScrollViewer.ScrollChanged="dgOrders_ScrollChanged" DockPanel.Dock="Top" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible"  Name="dgOrders" ItemsSource="{Binding delivery_orders_list}" CanUserDeleteRows="False" CanUserAddRows="False" IsReadOnly="True" AutoGenerateColumns="False"  Style="{StaticResource AzureDataGrid}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" SelectionChanged="dgOrders_OnSelectionChanged" Height="450" SelectedIndex="{Binding orders_index}">

    <DataGrid.RowStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding has_changed}" Value="True">
                    <Setter Property="Background" Value="LightSalmon"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </DataGrid.RowStyle>

    <DataGrid.Columns>
        <DataGridCheckBoxColumn Header="{x:Static resx:lang.order_is_printed}" Binding="{Binding is_printed}"/>
        <DataGridTextColumn Header="{x:Static resx:lang.serie}" Binding="{Binding series.serie}" />
        <DataGridTextColumn Header="{x:Static resx:lang.order_number}" Binding="{Binding order_number}"/>
        <DataGridTextColumn Header="{x:Static resx:lang.commensal}" Binding="{Binding commensal.contact_name}" />
    </DataGrid.Columns>

</DataGrid>

如果删除DataGrid.RowStyle标记,则SelectionUnit将恢复正常。

可能会发生什么?

PS:我正在使用适用于UI的MahApps.Metro库。

0 个答案:

没有答案