如何以编程方式访问ItemPanel?

时间:2010-10-18 06:36:31

标签: wpf

如何在代码后面访问listviews面板?

Xaml定义:

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

如果我命名面板,在代码隐藏中引用它时会出现编译时错误。

1 个答案:

答案 0 :(得分: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;
}