第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何更改 DataGrid 選定的行顏色 WPF

如何更改 DataGrid 選定的行顏色 WPF

C#
嗶嗶one 2022-01-09 17:06:57
我在我的 WPF 應用程序中創(chuàng)建了一個數(shù)據(jù)網格。我想更改選定的行顏色。我有以下代碼<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                    xmlns:local="clr-namespace:navigationApp.Resources">    <Style x:Key="DataGridColumnHeaderGripper" TargetType="Thumb">        <Setter Property="Width" Value="18"/>        <Setter Property="Background" Value="#252526"/>        <Setter Property="Template">            <Setter.Value>                <ControlTemplate TargetType="{x:Type Thumb}">                    <Border Padding="{TemplateBinding Padding}" Background="Transparent" BorderBrush="#3e3e45">                        <Rectangle HorizontalAlignment="Center" Width="1" Fill="{TemplateBinding Background}"/>                    </Border>                </ControlTemplate>            </Setter.Value>        </Setter>    </Style>    <Style TargetType="{x:Type DataGridCell}">        <Setter Property="Padding" Value="8,5" />        <Setter Property="FocusVisualStyle" Value="{x:Null}" />        <Setter Property="Template">            <Setter.Value>                <ControlTemplate TargetType="{x:Type DataGridCell}">                    <Grid Background="Transparent">                        <ContentPresenter                            Margin="{TemplateBinding Padding}"                            Content="{TemplateBinding ContentControl.Content}"                            ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"                            ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"                            SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />                    </Grid>                </ControlTemplate>            </Setter.Value>        </Setter>    </Style>當前,選定的行顏色為白色或透明。所以我看不到所選行的詳細信息。
查看完整描述

2 回答

?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

您可以使用觸發(fā)器更改所選行的顏色。如datagridrow樣式所示。選擇行時,將顏色設置為父控件的背景屬性(即 Grid 作為 TargetName)。


<Style TargetType="{x:Type DataGridRow}">       

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type DataGridRow}">

                    <Grid x:Name="selectedRow">                        

                            <DataGridCellsPresenter

                                ItemsPanel="{TemplateBinding ItemsControl.ItemsPanel}"

                                SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"

                                Grid.Column="1" />

                            <DataGridDetailsPresenter

                                Visibility="{TemplateBinding DataGridRow.DetailsVisibility}"

                                Grid.Column="1"

                                Grid.Row="1"

                                SelectiveScrollingGrid.SelectiveScrollingOrientation="Both" />

                            <DataGridRowHeader

                                Visibility="Visible"

                                Grid.RowSpan="2"

                                SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" />

                        </SelectiveScrollingGrid>

                    </Grid>

                    <ControlTemplate.Triggers>                                                        

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="{DynamicResource ApplicationAccentBrushSecondary}" TargetName="selectedRow" />

                        </Trigger>

                    </ControlTemplate.Triggers>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>


查看完整回答
反對 回復 2022-01-09
?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

在我的項目中,我做了如下:


<Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource DataGridCell}">

<Setter Property="Background" Value="{StaticResource DataGridCellBackgroundBrush}"/>

<Setter Property="BorderBrush" Value="{StaticResource DataGridBorderBrush}" />

<Setter Property="BorderThickness" Value="0"/>


<Style.Triggers>

    <!--  IsSelected  -->

    <Trigger Property="IsSelected" Value="True">

        <Setter Property="Foreground" Value="{StaticResource BlackBrush}" />

    </Trigger>

    <MultiTrigger>

        <MultiTrigger.Conditions>

            <Condition Property="Controls:DataGridCellHelper.IsCellOrRowHeader" Value="True" />

            <Condition Property="IsSelected" Value="True" />

        </MultiTrigger.Conditions>

        <Setter Property="Background" Value="{StaticResource DataGridCellBackgroundBrush}" />

        <Setter Property="BorderBrush" Value="{StaticResource DataGridCellBackgroundBrush}" />

    </MultiTrigger>

//others properties 

DataGridCellBackgroundBrush而DataGridBorderBrush在我的顏色預定


查看完整回答
反對 回復 2022-01-09
  • 2 回答
  • 0 關注
  • 942 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號