wpf – MVVM绑定viewmodel属性child to viewmodel属性

wpf – MVVM绑定viewmodel属性child to viewmodel属性,第1张

概述不确定我的标题是否能很好地解释我的问题. 在我的应用程序中,我打电话给服务 – 检查客户列表. – 检索组织列表. 然后我将这个客户列表绑定到我的视图上的列表框中. 在我的viewmodel中,我有以下属性: IEnumerable<Organisation> Organisations ObservableCollection<Customer> Customers 组织属性:Organisa 不确定我的标题是否能很好地解释我的问题.

在我的应用程序中,我打电话给服务
– 检查客户列表.
– 检索组织列表.

然后我将这个客户列表绑定到我的视图上的列表框中.

在我的viewmodel中,我有以下属性:

IEnumerable<Organisation> Organisations ObservableCollection<Customer> Customers

组织属性:OrganisationID,Organisationname

客户属性:CustomerID,OrganisationID,CustomerFirstname,CustomerLastname

在我的视图中的列表框内,我想显示列表中每个客户的组织名称.

我怎么能在我看来绑定这个?我只想要一个文本块来显示客户的组织名称.

解决方法 我在客户viewmodel中展平了Model:

class Customerviewmodel : INotifyPropertyChanged{    public string Orgname { get; }    public string Firstname {get; }    public string Lastname { get; }}

然后拥有的viewmodel返回Customers集合:

public class Storeviewmodel : INotifyPropertyChanged{    public ObservableCollection<Customerviewmodel> Customers { get; }}

将ListBox绑定到Customerviewmodel上的Orgname属性:

<ListBox>    <ListBox.ItemTemplate>        <DataTemplate>            <StackPanel>                <TextBlock Text="{Binding Firstname}"/>                <TextBlock Text="{Binding Orgname}"/>            </StackPanel>        </DataTemplate>    </ListBox.ItemTemplate></ListBox>
总结

以上是内存溢出为你收集整理的wpf – MVVM绑定viewmodel属性child to viewmodel属性全部内容,希望文章能够帮你解决wpf – MVVM绑定viewmodel属性child to viewmodel属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1004750.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存