[英]How do I refer to a control in a WPF nested ListView?
My XAML: 我的XAML:
<ListView x:Name="lvAlbums" ItemsSource="{Binding XPath=/downloads/Album}" SelectionMode="Multiple">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="spAlbum">
<!-- Displays first level attributes -->
<TextBlock x:Name="AlbumName" Text="{Binding XPath=@Name}"/>
<TextBlock x:Name="AlbumArtist" Text="{Binding XPath=@Artist}"/>
<ListView x:Name="lvTracks" ItemsSource="{Binding XPath=Item}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="spTrack">
<!-- Displays the second level attributes -->
<TextBlock x:Name="trackName" Text="{Binding XPath=@Name}"/>
<ProgressBar x:Name="pb1" Minimum="0" Maximum="100" Height="5px" Margin="0,0,0,0"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
It populates just fine from an xml file. 它从xml文件中填充得很好。 I have an album and listed underneath are the tracks and a progress bar for each track.
我有一张专辑,下面列出了每首曲目的曲目和进度条。
I am now looping though the XML to download each track. 我现在循环使用XML来下载每个轨道。 How do I refer to the progressbar?
我如何参考进度条?
(ProgressBar)lvAlbums[curAlbum].lvTracks[curTrack].spTrack["pb1"] (进度条)lvAlbums [curAlbum] .lvTracks [curTrack] .spTrack [ “PB1”]
Something like that. 这样的事情。
Please see if this works for you : 请查看这是否适合您:
var innerListView = lvAlbums.ItemTemplate.FindName("lvTracks", lvAlbums) as ListView;
ProgressBar pbar = innerListView.ItemTemplate.FindName("pb1", innerListView ) as ProgressBar;
Instead of trying to reference the progressbar control, I simply bound data to it and updated the data: 我只是将数据绑定到它并更新数据,而不是尝试引用进度条控件:
<ProgressBar x:Name="pb1" Value="{Binding XPath=@Progress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Minimum="0" Maximum="100" Height="5px" Margin="0,0,0,0" Width="145"/>
Works as expected. 按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.