Windows phone 7 将艺术家从ArtistCollection绑定到Windows Phone 7上的PanoramaItem.Listbox
如何将Windows phone 7 将艺术家从ArtistCollection绑定到Windows Phone 7上的PanoramaItem.Listbox,windows-phone-7,collections,panorama-control,media-library,Windows Phone 7,Collections,Panorama Control,Media Library,如何将艺术家集合中的所有艺术家绑定到全景项目中的列表框? 我的xaml如下所示: 和xaml.cs代码: private void phoneapplication页面\u已加载(对象发送方、路由目标方) { MediaLibrary=新的MediaLibrary(); int CountArtist=library.Artists.Count; //将library.Artister绑定到全景项目 } 谢谢 你试过了吗 artistLb.DataContext = library.Art
艺术家
集合中的所有艺术家绑定到全景项目中的列表框
?
我的xaml如下所示:
和xaml.cs代码:
private void phoneapplication页面\u已加载(对象发送方、路由目标方)
{
MediaLibrary=新的MediaLibrary();
int CountArtist=library.Artists.Count;
//将library.Artister绑定到全景项目
}
谢谢 你试过了吗
artistLb.DataContext = library.Artists;
你试过了吗
artistLb.DataContext = library.Artists;
在我的回答中,我假设您是从一个Windows Phone Panorama项目开始的,并且已经添加了对Microsoft.Xna.Framework的引用以访问媒体库
当将Ui对象(如ListBox)绑定到代码隐藏时,最好的解决方案是坚持项目中已经提供的ViewModel方法。在项目中,您应该可以找到MainViewModel。在此viewmodel中添加以下属性:
private MediaLibrary _library;
public MediaLibrary Library
{
get
{
if (_library == null)
{
_library = new MediaLibrary();
}
return _library;
}
}
此属性向您的xaml公开MediaLibrary。该库在第一次调用时被实例化
现在可以从您的xaml绑定到此属性,我只显示ListBox
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Library.Artists}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
请注意,我正在将列表框绑定到刚才在viewmodel中创建的库属性的子属性艺术家。我编辑了ItemTemplate,只显示一个绑定到艺术家姓名的文本块
在你的模拟器上,你会看到一个艺术家作为一个例子,要用一个真实的设备测试这个解决方案,你必须使用WPConnect工具,这已经解释过了
我希望您现在就可以开始,如果还有任何问题,请告诉我。在我的回答中,我假设您是从Windows Phone Panorama项目开始的,并且已经添加了对Microsoft.Xna.Framework的引用以访问媒体库
当将Ui对象(如ListBox)绑定到代码隐藏时,最好的解决方案是坚持项目中已经提供的ViewModel方法。在项目中,您应该可以找到MainViewModel。在此viewmodel中添加以下属性:
private MediaLibrary _library;
public MediaLibrary Library
{
get
{
if (_library == null)
{
_library = new MediaLibrary();
}
return _library;
}
}
此属性向您的xaml公开MediaLibrary。该库在第一次调用时被实例化
现在可以从您的xaml绑定到此属性,我只显示ListBox
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Library.Artists}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
请注意,我正在将列表框绑定到刚才在viewmodel中创建的库属性的子属性艺术家。我编辑了ItemTemplate,只显示一个绑定到艺术家姓名的文本块
在你的模拟器上,你会看到一个艺术家作为一个例子,要用一个真实的设备测试这个解决方案,你必须使用WPConnect工具,这已经解释过了
我希望这能让你马上开始,如果还有任何问题,请告诉我。我使用:artistLb.ItemsSource=library.Artists;然后在xaml中:我使用:artistLb.ItemsSource=library.Artists;然后在xaml中: