Binding static class to ListBox and TextBlock

╄→гoц情女王★ 提交于 2019-12-11 22:35:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!