在ListView中处理SwapchainPanel

发布于 2025-01-25 04:18:25 字数 1406 浏览 0 评论 0原文

我的XAML代码

<ListView x:Name="ListVideo"
              ItemsSource="{x:Bind ScreenList}"
              VerticalAlignment="Stretch"
              FlowDirection="LeftToRight"
              Grid.Row="1"
              ScrollViewer.VerticalScrollBarVisibility="Hidden"
              ScrollViewer.HorizontalScrollBarVisibility="Hidden">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <controls:UniformGrid></controls:UniformGrid>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Background="White"
                      BorderBrush="White"
                      BorderThickness="1">
                    <SwapChainPanel x:Name="swapChain"
                                    
                                    VerticalAlignment="Stretch"
                                    HorizontalAlignment="Stretch"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate></ListView>

带有screenlistobservableCollection的类型。因此,问题是如何在listView中添加新的swapchainpanel

我打算添加swapchainpanel项目,并且在每个项目中,我都使用DirectX渲染视频,因此我想在代码范围内将Object SwapchainPanel项目进行处理。

谢谢。

I have my xaml code

<ListView x:Name="ListVideo"
              ItemsSource="{x:Bind ScreenList}"
              VerticalAlignment="Stretch"
              FlowDirection="LeftToRight"
              Grid.Row="1"
              ScrollViewer.VerticalScrollBarVisibility="Hidden"
              ScrollViewer.HorizontalScrollBarVisibility="Hidden">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <controls:UniformGrid></controls:UniformGrid>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Background="White"
                      BorderBrush="White"
                      BorderThickness="1">
                    <SwapChainPanel x:Name="swapChain"
                                    
                                    VerticalAlignment="Stretch"
                                    HorizontalAlignment="Stretch"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate></ListView>

with ScreenList is type of ObservableCollection. So the question is how can I add new SwapChainPanel in the ListView?.

I intend to add SwapChainPanel item, and with each item I use DirectX to render video, so i want to get the object SwapChainPanel item in code-behind to process then.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久隐师 2025-02-01 04:18:25

所以问题是如何在listView

中添加新的SwapchainPanel

在ListView DataTemplate中放置的swapchainpanel的ListView中添加新的SwapchainPanel,而当前ListView itemssource is observableCollection。因此,您只需要将新项目添加到ObservableCollection中,ListView将自动渲染新项目。

所以我想在code-behind

中获取对象swapchainpanel项目

You could get itemContainer with

var container = MyList.ContainerFromItem(MyList.Items[0]) as ListViewItem;
var swapChain = (container.ContentTemplateRoot as Grid).FindName("swapChain");

更新

作为Hoka Biu评论,您还可以在Swapchainpanel加载事件中获得Swapchain实例。

<SwapChainPanel Loaded="swapChain_Loaded"/>

private void swapChain_Loaded(object sender, RoutedEventArgs e)
{
    var swapChain = sender as SwapChainPanel;         
}

So the question is how can I add new SwapChainPanel in the ListView

You have placed SwapChainPanel in the Listview DataTemplate, and current listview ItemsSource is ObservableCollection. So you just need add new item into ObservableCollection, the listview will render new item automatically.

so i want to get the object SwapChainPanel item in code-behind

You could get itemContainer with ContainerFromItem method, and find swapChain with name in ContentTemplateRoot.

var container = MyList.ContainerFromItem(MyList.Items[0]) as ListViewItem;
var swapChain = (container.ContentTemplateRoot as Grid).FindName("swapChain");

Update

As the Hoka Biu comment below, you could also get swapChain instance within SwapChainPanel Loaded event.

<SwapChainPanel Loaded="swapChain_Loaded"/>

private void swapChain_Loaded(object sender, RoutedEventArgs e)
{
    var swapChain = sender as SwapChainPanel;         
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文