问题
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 --
How to bind to the following :
- MyProfile.Friends To List Box which Contains Text blocks to have Friends Names
- MyProfile.Profile.Name To Textblock
回答1:
Make sure you define a namespace in your xaml to your C# namespace. I've named it local.
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 To Textblock
<TextBlock Text="{Binding Source={x:Static local:MyProfile.Profile.Name}" />
来源:https://stackoverflow.com/questions/6087219/binding-static-class-to-listbox-and-textblock