0
ItemsSource="{Binding Source={StaticResource stringResources}, Path=MyProp}"
我試過找來至今的數據綁定,但我不明白編譯:如何表達這個XAML組合框在C#代碼
comboBox.ItemsSource = new Binding { Source = new StringResources(), ElementName = "MyProp" };
comboBox.DisplayMemberPath="Value";
comboBox.SelectedValuePath="Key";
它說,它不能轉換結合IEnumerable和我不知道如何構建一個PropertyPath,所以我使用了ElementName,但我不知道這是否相同。
StringResources是一個具有屬性MyProp的類,它返回一個Dictionary。
感謝它現在很好用!我還注意到,在添加綁定之前分配DisplayMemberPath和SelectedValuePath *非常重要,否則它將不起作用。 – codymanix 2009-10-25 20:09:03