2009-08-07 8 views
5

मैं चांदी की रोशनी 3 डाटाग्रिड का उपयोग कर रहा हूं, और इसके भीतर, मैं rowdetails (visibilitymode = visualwhenselected) का उपयोग करके किसी अन्य नियंत्रण में संबंधित रिकॉर्ड घोंसला कर रहा हूं।नेस्टेड सिल्वरलाइट डाटाग्रिड - पंक्ति विवरण बहुत अच्छा काम करता है, लेकिन मुझे एक बटन चाहिए!

मुझे वास्तव में यह पसंद है कि यह कैसे काम करता है, लेकिन जब मैं एक नोड पर क्लिक करता हूं तो एक पेड़ विस्तारित होने पर ग्रिड पंक्ति विवरण प्रदर्शित करता है, जितना अधिक होगा।

मैं प्रोग्राम के रूप में इस तरह संसाधनों का उपयोग करके टेम्पलेट परिभाषित करने की कोशिश की:

<Grid.Resources> 
    <DataTemplate x:Key="EmptyTemplate"> 
     <StackPanel> 
      <!--<TextBlock Text="Empty Template!!!" />--> 
     </StackPanel> 
    </DataTemplate> 
    <DataTemplate x:Key="SongTemplate"> 
     <StackPanel> 
      <AdminControls:ArtistSongControl x:Name="ArtistSongControl" /> 
     </Stack> 
    </DataTemplate> 
</Grid.Resources> 

और ग्रिड के LoadingRowDetails घटना में, मैं जो खाका तैयार का निर्णय लेना होगा द्वारा:

e.Row.DetailsTemplate = (DataTemplate)LayoutRoot.Resources["SongTemplate"]; 

यह sortof काम , लेकिन मैंने पाया कि मुझे पिछली पंक्तियों के विवरण टेम्पलेट को ध्वस्त करने में समस्याएं थीं, और यहां तक ​​कि क्रैश किया गया था 8 (सुनिश्चित नहीं है कि यह संबंधित है)।

असल में, मुझे वास्तव में पसंद है कि चांदी की रोशनी 3 डाटाग्रिड कैसे काम करती है, और यहां तक ​​कि कैसे rowdetailstemplate सामान लागू किया जाता है। जब तक पंक्ति को जानबूझकर विस्तारित नहीं किया जाता है (जैसे पेड़ होगा) मैं बस किसी भी विवरण को लोड करना चाहता हूं। सभी तृतीय पक्ष ग्रिड ऐसा करने लगते हैं, और माइक्रोसॉफ्ट बहुत करीब है। क्या किसी को यह पता है कि इसे कैसे हल किया जाए?

धन्यवाद, डेनिस

उत्तर

6

डेनिस,

मामले में आप पहले से ही इस का उत्तर नहीं मिला है, मैं एक ही व्यवहार करना चाहता था और RowHeaderTemplate, की सुविधा देता है जो आप में एक बटन फेंक को अनुकूलित करके इसे हल प्रत्येक पंक्ति के लिए शीर्षलेख।

private void ToggleButton_Click(object sender, System.Windows.RoutedEventArgs e) 
{ 
    ToggleButton button = sender as ToggleButton; 
    DataGridRow row = button.GetVisualAncestorOfType<DataGridRow>(); 

    if (button.IsChecked == true) 
    { 
     row.DetailsVisibility = Visibility.Visible; 

     //Hide any already expanded row. We only want one expanded at a time for simplicity and 
     //because it masks a virtualization bug in the datagrid. 
     if (_expandedRow != null) 
      _expandedRow.DetailsVisibility = Visibility.Collapsed; 

     _expandedRow = row; 
    } 
    else 
    { 
     row.DetailsVisibility = Visibility.Collapsed; 
     _expandedRow = null; 
    } 
} 

नोट GetVisualAncestorOfType <> एक विस्तार विधि मैं दृश्य पेड़ में खुदाई करने के लिए लगाए गए हैं कि: तब मैं बहुत की तरह बटन के लिए कोई हैंडलर कार्यान्वित किया।

तुम भी datagrid के HeadersVisibility संपत्ति पंक्ति को सेट करना होगा या सभी

+0

बस कैसे सोच जब आप किसी नई पंक्ति के बटन पर क्लिक करते हैं तो उस पंक्ति पर टॉगलबटन को अचयनित करने के बारे में आप जाते हैं? –

0

मैं तुम्हें, datagrid पर RowVisibilityChanged घटना पर एक नज़र डालें मूल रूप से जब पंक्ति दृश्यता परिवर्तन सुझाने के लिए "दृश्यमान", तो लोड पंक्ति के लिए जानकारी।

डेटा ग्रिड इस तरह एक LoadingRow ईवेंट सेट अप में:

<data:DataGrid LoadingRow="ItemsGrid_LoadingRow" ..... 

डेटा ग्रिड में एक खाका स्तंभ है जो एक में शामिल होंगे बनाने

1

यहाँ एक और तरीका प्राप्त करने के लिए आपको बस इतना करना कोशिश कर रहे हैं क्या है

<data:DataGridTemplateColumn CellStyle="{StaticResource DataGridCellStyle1}" CanUserReorder="False"> 
     <data:DataGridTemplateColumn.CellTemplate> 
      <DataTemplate> 
        <Button x:Name="ViewButton" Click="ToggleRowDetailsVisibility" Cursor="Hand" Content="View Details" />          
      </DataTemplate> 
     </data:DataGridTemplateColumn.CellTemplate> 
     </data:DataGridTemplateColumn> 

LoadingRow घटना बटन है कि (इस मामले में) का पता लगाने डेटा ग्रिड का पहला स्तंभ में संग्रहीत में, तो CUR की दुकान: जैसे कि निम्न बटन बटन टैग तत्व

private void ItemsGrid_LoadingRow(object sender, DataGridRowEventArgs e) 
    { 
     var ViewButton = (Button)ItemsGrid.Columns[0].GetCellContent(e.Row).FindName("ViewButton"); 
     ViewButton.Tag = e.Row; 
    } 

बटन eventhandler में में DataGridRow किराए ताकि हम टॉगल कर सकते हैं हम पंक्ति निकाल देंगे (इस मामले ToggleRowDetailsVisibility में) ने अपने DetailsVisibility

In the LoadingRow Event locate the button that is (in this case) stored in the first column of the DataGrid, then store the current DataGridRow into the buttons Tag element 

private void ToggleRowDetailsVisibility(object sender, RoutedEventArgs e) 
    { 
     var Button = sender as Button; 
     var Row = Button.Tag as DataGridRow; 

     if(Row != null) 
     { 
      if(Row.DetailsVisibility == Visibility.Collapsed) 
      { 
       Row.DetailsVisibility = Visibility.Visible; 

       //Hide any already expanded row. We only want one expanded at a time for simplicity and 
       //because it masks a virtualization bug in the datagrid. 
       if (CurrentlyExpandedRow != null) 
       { 
        CurrentlyExpandedRow.DetailsVisibility = Visibility.Collapsed; 
       } 

       CurrentlyExpandedRow = Row; 
      } 
      else 
      { 
       Row.DetailsVisibility = Visibility.Collapsed; 
       CurrentlyExpandedRow = null; 
      } 
     } 
    } 

आपको लगता है कि "CurrentlyExpandedRow" देखेंगे , यह एक ग्लोबल वैरिएबल है, टाइपग्रिडरो प्रकार का, हम वर्तमान में विस्तारित पंक्ति को स्टोर करते हैं, इससे हमें उस पंक्ति को बंद करने की अनुमति मिलती है जब कोई नया खोला जाता है।

उम्मीद है कि इससे मदद मिलती है।

DataGridRow row = button.GetVisualAncestorOfType<DataGridRow>(); 

हम के रूप में उपयोग कर सकते हैं:

1

यहाँ प्रदान जवाब uxrx के अलावा इस के लिए एक पूर्वज

public static partial class Extensions 
{ 
    public static T FindAncestor<T>(DependencyObject obj) where T : DependencyObject 
    { 
     while (obj != null) 
     { 
      T o = obj as T; 
      if (o != null)    
       return o; 

      obj = VisualTreeHelper.GetParent(obj); 
     } 
     return null; 
    } 

    public static T FindAncestor<T>(this UIElement obj) where T : UIElement 
    { 
     return FindAncestor<T>((DependencyObject)obj); 
    } 
} 
1

को खोजने के लिए कोड है

HyperlinkButton button = sender as HyperlinkButton;  
DataGridRow Row = DataGridRow.GetRowContainingElement(button) 
संबंधित मुद्दे