2011-11-30 15 views
5

मैं एक डाटाटेबल स्टाइल कर रहा हूं लेकिन मुझे पता नहीं लगा सकता कि डेटाग्रिड के दायर दाएं कोने के तरीके को कैसे शैलीबद्ध किया जाए। यह इस चित्र में ग्रे क्षेत्र है:स्टाइल डेटाग्रिड टेबल - टॉप बाएं कोने

enter image description here

आप इसे कैसे करना जानते हैं?

यहाँ अब तक मेरी शैली है:

<Style TargetType="{x:Type DataGrid}"> 
    <Setter Property="Margin" Value="5" /> 
    <Setter Property="Background"> 
     <Setter.Value> 
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
       <GradientStop Color="White"/> 
       <GradientStop Color="AliceBlue" Offset="1"/> 
      </LinearGradientBrush> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="RowBackground"> 
     <Setter.Value> 
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
       <GradientStop Color="#BAF0FF"/> 
       <GradientStop Color="PowderBlue" Offset="1"/> 
      </LinearGradientBrush> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="AlternatingRowBackground"> 
     <Setter.Value> 
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
       <GradientStop Color="White"/> 
       <GradientStop Color="AliceBlue" Offset="1"/> 
      </LinearGradientBrush> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="HorizontalGridLinesBrush" Value="LightGray" /> 
    <Setter Property="VerticalGridLinesBrush" Value="LightGray" /> 
</Style> 
+1

आप में 'RowHeaders' की ज़रूरत है अपने डेटा ग्रिड? यदि नहीं, तो मैं उन्हें पूरी तरह से हटाने की सिफारिश करता हूं (' 'टैग पर' शीर्षलेख दृश्यता =" कॉलम "सेट करें) ताकि कोने सेल दिखाई न दे। – Rachel

+3

हां मुझे उनकी ज़रूरत है। – Sulby

उत्तर

2

इस answer से मैं इस कोड है जो सही ढंग से बटन की शैली सेट बनाने के लिए कर रहा था:
यहाँ मेरे कार्य कोड है

<DataGrid>  
    <DataGrid.Resources> 
     <Style TargetType="Button" x:Key="{ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}"> 
      <Setter Property="Background" Value="Black" /> 
     </Style> 
    </DataGrid.Resources> 
</DataGrid> 
1

मैं एक अपूर्ण लेकिन काम कर समाधान मिल गया।
आप VisualTreeHelper द्वारा डेटाग्रिड के "शीर्ष बाएं कोने" ऑब्जेक्ट को प्राप्त कर सकते हैं। जो वास्तव में एक बटन है। मुझे लगता है कि आप जानते हैं कि आगे कैसे करें।

//Change the top left button to a CheckBox 
void StyleSelectAllButton(DependencyObject dependencyObject) 
{ 
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObject); i++) 
    { 
     var child = VisualTreeHelper.GetChild(dependencyObject, i); 
     if ((child != null) && child is Button) 
     { 
      var grid = (Grid)VisualTreeHelper.GetChild(child, 0); 

      var checkBox = new CheckBox() 
      { 
       VerticalAlignment = VerticalAlignment.Center, 
       HorizontalAlignment = HorizontalAlignment.Center, 
      }; 

      checkBox.Click += OnCheckBoxClicked; 

      grid.Children.Clear(); 
      grid.Children.Add(checkBox); 
     } 
     else 
     { 
      StyleSelectAllButton(child); 
     } 
    } 
} 

//Action when the top left check box checked and unchecked 
void OnCheckBoxClicked(object sender, RoutedEventArgs e) 
{ 
    var checkBox = sender as CheckBox; 

    if (checkBox == null) 
    { 
     return; 
    } 

    if (checkBox.IsChecked == true) 
    { 
     //Change the 'dataGrid' to your DataGrid instance name 
     dataGrid.SelectAllCells(); 
    } 
    else 
    { 
     //Change the 'dataGrid' to your DataGrid instance name 
     dataGrid.UnselectAllCells(); 
    } 
} 

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^