如何从 ListViewItem 获取 ProgressRing?

How to get ProgressRing from ListViewItem?

我有一个带有以下 ItemTemplate 的 ListView

<ListView.ItemTemplate>
                <DataTemplate x:DataType="model:SubsceneDownloadModel">
                    <UserControl PointerEntered="ListViewSwipeContainer_PointerEntered" 
                                 PointerExited="ListViewSwipeContainer_PointerExited">
                        
                        <Grid AutomationProperties.Name="{x:Bind Name}">
                            <SwipeControl x:Name="ListViewSwipeContainer" >
                                <Grid VerticalAlignment="Center">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{x:Bind Name}" 
                                               Margin="10,5,10,5" 
                                               FontSize="18" 
                                               HorizontalAlignment="Left" 
                                               VerticalAlignment="Center"/>

                                    <AppBarButton x:Name="DownloadHoverButton"
                                                  Margin="10,0,10,0"
                                                  HorizontalAlignment="Right"    
                                                  IsTabStop="False" 
                                                  Visibility="Collapsed"
                                                  Label="Download"
                                                  Icon="Download"
                                                  Click="DownloadHoverButton_Click"/>
                                   <ProgressRing x:Name="prgStatus"/>
                                </Grid>
                            </SwipeControl>
                        </Grid>
                    </UserControl>
                </DataTemplate>
            </ListView.ItemTemplate>

我希望在单击 AppBarButton 时更改 ProgressRing 的值,但问题是无法从项目模板访问 AppBarButton,那么如何从项目模板访问 Progressring?

将您的项目模板移动到新的用户控件

<UserControl
    Name="subsceneView"
    x:Class="HandySub.UserControls.SubsceneUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"
    PointerEntered="UserControl_PointerEntered"
    PointerExited="UserControl_PointerExited">
    
    <Grid>
       
        <SwipeControl x:Name="ListViewSwipeContainer" >
            <Grid AutomationProperties.Name="{x:Bind Name}">
                            <SwipeControl x:Name="ListViewSwipeContainer" >
                                <Grid VerticalAlignment="Center">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="auto"/>
                                        <RowDefinition Height="auto"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{x:Bind Name}" 
                                               Margin="10,5,10,5" 
                                               FontSize="18" 
                                               HorizontalAlignment="Left" 
                                               VerticalAlignment="Center"/>

                                    <AppBarButton x:Name="DownloadHoverButton"
                                                  Margin="10,0,10,0"
                                                  HorizontalAlignment="Right"    
                                                  IsTabStop="False" 
                                                  Visibility="Collapsed"
                                                  Label="Download"
                                                  Icon="Download"
                                                  Click="DownloadHoverButton_Click"/>
                                   <ProgressRing x:Name="prgStatus"/>
                                </Grid>
                            </SwipeControl>
                        </Grid>
        </SwipeControl>
    </Grid>
</UserControl>

并在您的列表视图中

<ListView.ItemTemplate>
                <DataTemplate x:DataType="model:SubsceneDownloadModel">
                    <usercontrol:SubsceneUserControl/>
                </DataTemplate>
            </ListView.ItemTemplate>