结合静态类ListBox和TextBlock的 [英] Binding static class to ListBox and TextBlock
本文介绍了结合静态类ListBox和TextBlock的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
User Class
- Name
- Picture
Friend Class
- Profile Of Type User
- Age
MyProfile STATIC Class
- STATIC Profile Of Type User
- STATIC Friends Collection Of Type Friend
- 编辑 -
-- EDIT --
如何结合到以下内容:搜索
- MyProfile.Friends要列表框,其中包含文本块有朋友名字结果
- MyProfile.Profile.Name为文本块
How to bind to the following :
- MyProfile.Friends To List Box which Contains Text blocks to have Friends Names
- MyProfile.Profile.Name To Textblock
推荐答案
请确保你定义在你的XAML命名空间到C#的命名空间。我把它命名为局部的。
Make sure you define a namespace in your xaml to your C# namespace. I've named it local.
MyProfile.Friends要列表框,其中包含文本块有朋友名字
MyProfile.Friends To List Box which Contains Text blocks to have Friends Names
<ListBox ItemsSource="{Binding Source={x:Static local:MyProfile.Friends}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Profile.Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
MyProfile.Profile.Name为文本块
MyProfile.Profile.Name To Textblock
<TextBlock Text="{Binding Source={x:Static local:MyProfile.Profile.Name}" />
这篇关于结合静态类ListBox和TextBlock的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文