0
我在將ObservableCollection
綁定到ComboBox
(RadComboBox
)時遇到了一些問題。我以前使用過幾乎相同的代碼,但現在由於某種原因,它不起作用(ComboBox
中沒有任何顯示)。將自定義對象的ObservableCollection綁定到ComboBox
這是我的ComboBox
代碼:
<telerik:RadComboBox ItemTemplate="{StaticResource ComboBoxServerPropertiesTemplate}" DataContext="{Binding libpm:Collection.Properties}" ItemsSource="{Binding Name}"/>
的DataTemplate
看起來是這樣的:
<DataTemplate x:Key="ComboBoxServerPropertiesTemplate">
<Grid Margin="0 3">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.ColumnSpan="2" Text="{Binding Name}" />
<TextBlock Grid.Row="1" Text="Value:" />
<TextBlock Grid.Row="1" Foreground="#FFA2D0FF" Margin="40,0,0,0" Text="{Binding Value}" />
</Grid>
</DataTemplate>
的Collection()
看起來是這樣的:
public static class Collection
{
public static ObservableCollection<ServerProperties.Property> Properties { get; set; }
}
而且ServerPropeties.Property
看起來像這樣:
public sealed class Property
{
public string Name { get; set; }
public string Value { get; set; }
}
我嘗試使用"{Binding Path=libpm:Collection.Properties}"
兩個DataContext
和ItemSource
,我也試圖把"{Binding libpm:Collection.Properties}"
爲ItemSource
,但它不工作。
任何幫助,將不勝感激。
拋出異常顯示
Name
財產:'不能同時設置DisplayMemberPath和ItemTemplate.' – davidwroxy 2013-05-11 14:04:29對,如果您使用的是ItemTemplate,則不能使用DisplayMemberPath。選擇一個或另一個。 – Xcalibur37 2013-05-11 14:23:41
我也試過,但它不起作用。 – davidwroxy 2013-05-11 14:26:22