访问Wpf datagrid ContainerStyle

时间:2013-03-06 06:52:36

标签: wpf datagrid

您好我想访问后面代码中的datagrid(下面的xaml)中找到的扩展器,请告诉我解决方案,提前致谢

我的xaml代码如下:

<dg:DataGrid Margin="0,14,0,0"  Grid.Row="1" BorderThickness="0" PreviewMouseLeftButtonDown="mouse_Downs"   MouseDoubleClick="CustomDataGrid_MouseDoubleClick"  RowEditEnding="CustomDataGrid_RowEditEnding" Grid.RowSpan="6" AlternationCount="2"  SelectionMode="Single" SelectionUnit="FullRow" x:Name="CustomDataGrid" CanUserResizeColumns="False" AutoGenerateColumns="False" SelectionChanged="CustomDataGrid_SelectionChanged" ColumnHeaderStyle="{StaticResource columnHeaderStyle}" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="False" RowStyle="{StaticResource DataGridRowStyle}" GridLinesVisibility="None"  HeadersVisibility="Column"  CanUserSortColumns="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <dg:DataGrid.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Name}" FontFamily="Calibri" Foreground="#FF055B72" FontWeight="Bold" FontSize="11"/>
                    </StackPanel>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
            <GroupStyle.ContainerStyle>
                <Style TargetType="{x:Type GroupItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type GroupItem}">
                                <Expander Style="{StaticResource ExpanderStyle}"  x:Name="RowExpand" IsExpanded="True" Cursor="Hand" >
                                    <!--<Expander.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFC7C7C7" Offset="1"/>
                                            <GradientStop Color="#FFEAE9E9"/>
                                            <GradientStop Color="#FFEBE8E8" Offset="0.37"/>
                                        </LinearGradientBrush>
                                    </Expander.Background>-->
                                    <Expander.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock x:Name="txtGroupHeader" Text="{Binding Path=Name}" FontFamily="Calibri" Foreground="#FF47494F"  FontWeight="Bold" FontSize="14"/>
                                            <!--<Button Width="90" Height="25" Content="Sample"/>-->
                                        </StackPanel>
                                    </Expander.Header>
                                    <ItemsPresenter  Margin="7,5,7,9"/>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </dg:DataGrid.GroupStyle>

1 个答案:

答案 0 :(得分:0)

您无法直接以样式访问它。你能做的就是获得风格(比如这篇文章中的解释:Can i get the key of a style in code-behind? (WPF)),然后通过你的风格来访问扩展器对象。