2010-10-18 379 views
0

如何在後面的代碼中訪問listviews面板?如何以編程方式訪問ItemPanel?

XAML中定義:

 <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <telerik:RadCarouselPanel /> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 

如果我命名的面板,我在後臺代碼指的是當得到一個編譯時錯誤。

回答

1

一種方式做到這一點是存儲RadCarouselPanel當它被加載

<ListView.ItemsPanel> 
    <ItemsPanelTemplate> 
     <telerik:RadCarouselPanel Loaded="RadCarouselPanel_Loaded"/> 
    </ItemsPanelTemplate> 
</ListView.ItemsPanel> 

,並在後面的代碼

private RadCarouselPanel m_radCarouselPanel = null; 

private void RadCarouselPanel_Loaded(object sender, RoutedEventArgs e) 
{ 
    m_radCarouselPanel = sender as RadCarouselPanel; 
}