【发布时间】:2009-05-16 14:27:15
【问题描述】:
我在Window 中有以下内容(删除了不必要的部分):
XAML:
<Style x:Key="itemstyle" TargetType="{x:Type ContentPresenter}">
<EventSetter Event="MouseLeftButtonDown" Handler="HandleItemClick"/>
</Style>
<ItemsControl ItemsSource="{Binding ArtistList}" Margin="10" Name="artist_list" ItemContainerStyle="{StaticResource itemstyle}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ID}" Foreground="White"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Controls:RSSViewer x:Name="rssControl" />
C#(背后的代码):
private void HandleItemClick(object sender, MouseButtonEventArgs e)
{
var selectedArtist = ((ContentPresenter) sender).Content as Artist;
rssControl.SourceUrl = "http://agnt666laptop:28666/rss.aspx?artistid=" + selectedArtist.ID;
}
现在我想做的是将上述 xaml 和 C# 的混合转换为纯粹的 xaml,以利用 WPF 的 DataBinding 模型。
我认为它需要事件触发器和数据绑定与 itemscontrol 元素的选定项的组合或类似的东西,但我不确定如何去做。
谁能指导我如何转换上述解决方案以删除程序代码?
【问题讨论】:
标签: c# wpf xaml data-binding