0

我的视图模型上有一个公共常量字符串,我想绑定到

系统:字符串

在下面的 xaml 片段中:

<ComboBox.ItemsSource>
    <CompositeCollection>
       <sys:String></sys:String>
       <CollectionContainer Collection="{Binding VMCollection, Source={StaticResource proxy}}" />
    </CompositeCollection>
 </ComboBox.ItemsSource>

如果 String 有一个 content 属性或其他东西会很容易,但只是想找出最好的方法来做到这一点。

4

1 回答 1

2

就个人而言,我认为无论如何您都应该在 ViewModel 中组合这些选项(可用)。(这些不是应该“呈现”给用户的选项吗?即使你为此创建了一个全新的 UI,选项也会相同吗?)

但是要回答你的问题..

<Window ...
...
xmlns:local="clr-namespace:MyNamespace">

<ComboBox>
        <ComboBox.ItemsSource>
            <CompositeCollection>
                <x:StaticExtension Member="local:Constants.MyConst" />
                <core:String>1</core:String>
                <core:String>2</core:String>
                <core:String>3</core:String>
            </CompositeCollection>
        </ComboBox.ItemsSource>
    </ComboBox>

public static class Constants
{
    public static string MyConst
    {
        get
        {
            return "asd";
        }
    }
}

这有效

于 2013-01-25T22:36:15.703 回答