1

I am using an Xceed datagrid and I am trying to change the RowSelectorPane background color. I tried to do this in the XAML, but it would give me a compiler error stating that it cannot create my datagrid control. Any advice would be greatly appreciated.

<xcdg:DataGridControl Background="Transparent" Name="dgControl" SelectionUnit="Cell" >
    <!--<xcdg:RowSelectorPane Background="Transparent" />-->
</xcdg:DataGridControl>
Seb
  • 3,414
  • 10
  • 73
  • 106

1 Answers1

3

UPDATE 2: Browsing through the Xceed documentation and the Xceed fora I found out that you have to set the RowSelectorStyle on every DataRow.

     <Grid.Resources>            
        <Style x:Key="mySelectorStyle" TargetType="{x:Type xcdg:RowSelector}">
            <Setter Property="Background" Value="LightGreen"/>
            <Setter Property="BorderBrush" Value="DarkGreen"/>                
        </Style>

        <Style TargetType="{x:Type xcdg:DataRow}">
            <Setter Property="xcdg:RowSelector.RowSelectorStyle"
          Value="{StaticResource mySelectorStyle}" />
        </Style>

    </Grid.Resources>        

Update 3 You are right I missed the parts outside the rows section: the rowselectorpane itself. Unfortunately that is not styleable. There are 2 options:

  1. Rewrite the TableViewScrollViewer controltemplate as suggested on the Xceed forum. But this is tedious copy paste work of large parts of xaml and changing that little part you want to have it look your way.

  2. Or the following little hack:

    private void dataGridLoaded(object sender, RoutedEventArgs e)
    {
        var rowSelectorPane = TreeHelper.FindVisualChild<RowSelectorPane>(_dataGrid);
        if (rowSelectorPane != null)
        {
            rowSelectorPane.Background = Brushes.LightGreen;
        }
    }
    
    public static class TreeHelper
    {
        public static TChildItem FindVisualChild<TChildItem>(DependencyObject obj) where TChildItem : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(obj, i);
    
                if (child != null && child is TChildItem)
                    return (TChildItem)child;
    
                TChildItem childOfChild = FindVisualChild<TChildItem>(child);
    
                if (childOfChild != null)
                    return childOfChild;
            }
            return null;
        }
    }
    

Xaml: <xcdg:DataGridControl ItemsSource="{Binding}" Name="_dataGrid" Loaded="dataGridLoaded" etc...>

Grafix
  • 706
  • 4
  • 6
  • This seems to work half way as it only colors in RowSelectorPane on data rows. What about around the area of the ColumnManagerCells or the area where the data hasn't been set? Granted I am very grateful for your help and if those can't be modified then this will have to do – Seb Dec 06 '12 at 14:15
  • Looks like I have a lot of work ahead of me. Thank you so much for your help. – Seb Dec 06 '12 at 19:58