2013-09-26 30 views
1

我有一個WPF應用程序,它包含一個顯示訂單列表的數據網格。每個訂單都有一個ID,但可能有多個ID(由於某些原因,我無法控制)。WPF Datagrid RowHeader切換按鈕的選定行

所以我使用rowdetails來顯示嵌套數據網格中的ID列表。

我希望實現兩件事。

1)如果用戶點擊一行,它會自動展開並顯示行詳細信息&除非您單擊另一行,否則無法摺疊此行。因此,我希望在rowheader中的按鈕能夠顯示行詳細信息的可見性,並且如果用戶單擊該行,行詳細信息不會顯示。我只想要顯示行標記是否點擊行標題中的按鈕。

2)不是很重要,但如果它很容易實現,只有具有多個ID的行在行標題中有一個按鈕。

這裏是我的DataGrid代碼

<!-- 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">              
      <DataGrid.RowHeaderTemplate> 
       <DataTemplate> 
        <ToggleButton x:Name="RowHeaderToggleButton" 
            Cursor="Hand"/> 
       </DataTemplate> 
      </DataGrid.RowHeaderTemplate> 

在我的App.xaml,我做的造型我都這樣了,

<!-- 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> 
    </Style> 



    <!-- Toogle Button --> 
    <Style TargetType="ToggleButton"> 
     <Setter Property="Padding" Value="3" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ToggleButton"> 
        <Grid> 

         <ContentPresenter x:Name="contentPresenter" 
             Margin="{TemplateBinding Padding}" 
             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
             VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
             Content="{TemplateBinding Content}" 
             ContentTemplate="{TemplateBinding ContentTemplate}" /> 
         <Path x:Name="DefaultPath" 
          VerticalAlignment="Top" 
          Data="M0,0 14,7 0,14 Z" 
          Fill="Gray" 
          Stretch="Fill" /> 
         <Path x:Name="CheckedPath" 
          VerticalAlignment="Top" 
          Data="M0,0 14,0 7,14 Z" 
          Fill="LightGray" 
          Stretch="Fill" 
          Visibility="Collapsed" /> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
+0

什麼是你的問題? –

+0

如何爲每行的rowheader添加一個按鈕。所以顯示rowdetails的唯一方法就是點擊按鈕。目前,如果用戶點擊一行,該行將展開以顯示行細節。 – mHelpMe

回答