简体   繁体   中英

How to get ProgressRing from ListViewItem?

i have a ListView with following ItemTemplate

<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>

I want the value of the ProgressRing to change when I click on the AppBarButton but the problem is AppBarButton is not accessible from item template, so how can i access progressring from itemtemplate?

move your itemtemplate to a new usercontrol

<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>

and in your listview

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM