0

我有一个包含数据网格的 WPF 应用程序。我正在尝试将一个切换按钮添加到具有三角形的 datarowheader 中。形状应指向右侧,然后单击显示行详细信息,箭头应指向下方。

 <!-- The data grid to display orders-->
        <DataGrid DataContext="{Binding OrderBlock}" 
                  x:Name="dataGridOrders" 
                  ItemsSource="{Binding Orders}"
                  Style="{StaticResource DataGridTemplate}"
                  ColumnHeaderStyle="{StaticResource DG_ColumnHeader}"                      
                  RowHeaderStyle="{StaticResource DG_RowHeader}"
                  RowStyle="{StaticResource DG_Row}"
                  CellStyle="{StaticResource DG_Cell}"                      
                  RowDetailsTemplate="{StaticResource DG_RowDetail}"                      
                  AutoGenerateColumns="False"
                  HorizontalAlignment="Stretch" 
                  VerticalAlignment="Stretch"
                  Background="Silver"
                  RowHeaderWidth="30"                      
                  Margin="25,5,20,15"> 


<!-- Data Grid row header template -->
    <Style x:Key="DG_RowHeader" TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Width" Value="35"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <Border x:Name="DGRH_Border"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                <GradientStop Offset="0" Color="LightGray"/>
                                <GradientStop Offset="1" Color="WhiteSmoke"/>
                            </LinearGradientBrush>
                        </Border.Background>
                    </Border>                        
                </ControlTemplate>                         
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="M"/>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
4

1 回答 1

1

您可以为行标题使用具有类似这样的切换按钮的控件模板:

    <Style x:Key="DG_RowHeader" TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Width" Value="35"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <ToggleButton Content="button" x:Name="btn"/>
                    <ControlTemplate.Triggers>
                        <DataTrigger Value="True">
                            <DataTrigger.Binding>
                                <Binding ElementName="btn" Path="IsChecked"></Binding>
                            </DataTrigger.Binding>
                            <DataTrigger.Setters>
                                <Setter Property="Content" TargetName="btn" Value="-"/>
                            </DataTrigger.Setters>
                        </DataTrigger>
                        <DataTrigger Value="False">
                            <DataTrigger.Binding>
                                <Binding ElementName="btn" Path="IsChecked"></Binding>
                            </DataTrigger.Binding>
                            <DataTrigger.Setters>
                                <Setter Property="Content" TargetName="btn" Value="+"/>
                            </DataTrigger.Setters>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
于 2013-09-27T15:18:34.857 回答