我在将 an 绑定ObservableCollection 到ComboBox( RadComboBox) 时遇到了一些麻烦。我之前使用了几乎相同的代码,但现在,由于某种原因,它不起作用(没有出现在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}"forDataContext并且ItemSource我也尝试使用"{Binding libpm:Collection.Properties}"for ItemSource,但它不起作用。
任何帮助,将不胜感激。