English 中文(简体)
哥伦·赫纳德·斯特莱根据数据网的甄选情况的变化背景
原标题:Change background color of ColumnHeaderStyle based on selection in datagrid
  • 时间:2011-09-13 19:22:40
  •  标签:
  • c#
  • wpf

I figured out how to highlight the row of interest. I can get the index of the column I am interested in and use ScrollIntoView in order to jump to it. However, it doesn t immediately pop out to the user. I d like to highlight the column, or change the ColumnHeaderStyle. I can t seem to figure out how to do it in the xaml or code behind.

另一种选择是,不强调整个行和一栏标题,而只是利益单位。 我这样做了,但可以得出数字。

我目前的数据来源就是:

<DataGrid x:Name="dtGridReads"  AutoGenerateColumns="False" 
            VirtualizingStackPanel.IsVirtualizing="True"                                       
            VirtualizingStackPanel.VirtualizationMode ="Standard" 
              EnableColumnVirtualization="True"
              EnableRowVirtualization="True"
            ScrollViewer.IsDeferredScrollingEnabled="True"
            CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="True"
             ItemsSource ="{Binding}" Block.TextAlignment="Center"
             AlternatingRowBackground="#F1F1F1" RowBackground="White"
              CanUserAddRows="False" CanUserDeleteRows="False" FrozenColumnCount="1"
               GridLinesVisibility="None"                   ScrollViewer.ScrollChanged="dtGridReads_ScrollChanged">

    <DataGrid.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Style.Triggers>
                <Trigger Property="DataGridCell.IsSelected" Value="True">
                    <Setter Property="Background" Value="red" />
                    <Setter Property="BorderThickness" Value="0" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </DataGrid.CellStyle>

我的守则如下:

    public void ShowSelectedCell(int row, int column)
    {
        //dtGridReads.SelectedItem = dtGridReads.Items[row];
        //dtGridReads.SelectedItem = dtGridReads.Columns[column];
        //dtGridReads.CurrentColumn = dtGridReads.Columns[column];
        dtGridReads.ScrollIntoView(dtGridReads.Items[row], dtGridReads.Columns[column]);

    }

感谢。

最佳回答

假设你需要强调数据格栏标题,以选定重点电池为基础。

创建 范围式样:。 风格包括数据触发因素,如果一栏标题的内容和现有电池栏目的内容相同,即该栏标题属于现有电池所属的一栏。 如果我们改变主人的背景。

<toolkit:DataGrid x:Name="MyDataGrid"
      IsReadOnly="True"
      AutoGenerateColumns="False">
  <toolkit:DataGrid.Resources>
    <local:EqualityConverter x:Key="EqualityConverter"/>
    <Style TargetType="{x:Type toolkit:DataGridColumnHeader}">
      <Style.Triggers>
        <DataTrigger Value="True">
          <DataTrigger.Binding>
            <MultiBinding Converter="{StaticResource EqualityConverter}">
               <Binding Path="CurrentCell.Column.Header"
                  RelativeSource="{RelativeSource
                     AncestorType={x:Type toolkit:DataGrid}}"/>
                <Binding Path="Content"
                  RelativeSource="{RelativeSource Self}"/>
            </MultiBinding>
          </DataTrigger.Binding>
          <Setter Property="Background" Value="Red"/>
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </toolkit:DataGrid.Resources>
  <toolkit:DataGrid.Columns>
    <toolkit:DataGridTextColumn Header="Key"
           Binding="{Binding Key, Mode=OneWay}"></toolkit:DataGridTextColumn>
    <toolkit:DataGridTextColumn Header="Value"
           Binding="{Binding Value, Mode=OneWay}"></toolkit:DataGridTextColumn>
  </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

如果约束性价值观是平等的,那么仅仅是一个多约束性转换器......

public class EqualityConverter : IMultiValueConverter
{
    public object Convert(
            object[] values,
            Type targetType,
            object parameter,
            System.Globalization.CultureInfo culture)
    {
        if (values != null)
        {
            for (var i = 1; i < values.Count(); i++)
            {
                if (values[i] == null || !values[i].Equals(values[i-1]))
                {
                    return false;
                }
            }

            return true;
        }

        return false;
    }

    public object[] ConvertBack(
             object value,
             Type[] targetTypes,
             object parameter,
             System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

让我知道这是否有助于。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签