質問

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>
役に立ちましたか?

解決

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...>

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top