gpt4 book ai didi

silverlight - 如何在 Silverlight MVVM 中绑定(bind)子对象列表

转载 作者:行者123 更新时间:2023-12-03 10:30:27 25 4
gpt4 key购买 nike

在 Silverlight、MVVM 中,我必须创建一个属性窗口,但我只有一个List<AProperty>对象,其中 AProperty是一个带有一些子类的抽象类。

我想将它绑定(bind)到 Silverlight 控件(但绑定(bind)到哪个控件?),有一些条件:

  • 一些子属性必须显示为文本框,一些显示为复选框,一些显示为组合框。它来自动态类型。
  • AProperty 类有一个 PropertyGroupName field 。顺序必须是字母 ( PropertyGroup > Name )

  • 任何想法或工作示例?

    我的代码:
        public abstract class AProperty {
    private String _Name;
    private String _Caption;
    private String _PropertyGroup;

    public String Name {
    get { return _Name; }
    set { _Name = value; }
    }

    public String Caption {
    get { return _Caption; }
    set { _Caption = value; }
    }

    public String PropertyGroup {
    get { return _PropertyGroup; }
    set { _PropertyGroup = value; }
    }
    }
    List<AProperty> Properties;

    和 xaml:
    <ListBox ItemsSource="{Binding ... Properties ...}">
    <!-- Here order the items -->
    <ListBox.ItemTemplate>
    <DataTemplate>
    <StackPanel Orientation="Horizontal">
    <TextBlock Width="250"
    Text="{Binding Path=Caption}" />

    <!-- And here need I a textbox, or a checkbox, or a combobox anyway -->
    </StackPanel>
    </DataTemplate>
    </ListBox.ItemTemplate>
    </ListBox>

    我发现值转换器仅用于控制属性,而不是用于整个堆栈面板内容。

    最佳答案

    您可以使用值转换器来检查对象是什么类型并返回正确的控件类型。

    你有任何示例代码,所以我可以举一个更好的例子吗?

    关于silverlight - 如何在 Silverlight MVVM 中绑定(bind)子对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045222/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com