我有一个集合ObservableCollection <FeatureLayer> FeatureLayerList
和ObservableCollection <TextBlock> TextBlock
。
我需要一个用于Combobox
的DataTemplate来显示FeatureLayerList
和DataTemplate中的项目以显示来自TextBlock
的项目。
显示DataTempales需要这样,如果空集合FeatureLayerList
显示集合TextBlock
的DataTemplate,这是一个点击的元素,它应该为您提供一个表单,该表单将在集合FeatureLayerList
中添加项目,添加集合中的项目后,必须关闭添加项目的表单,并显示DataTemplate集合FeatureLayerList以及添加的元素。
我不了解我的集合的DataTemplates种类,以及如何在它们之间切换。
向我解释如何使用DataTemplate for Combobox,以及如何根据条件在DataTemplates之间切换。
<ComboBox x:Name="FeatureLayerComboBox" Validation.ErrorTemplate="{x:Null}" Margin="0, 2, 0, 10" SelectedItem="{Binding SelectedFeatureLayer}" ItemsSource="{Binding FeatureLayerList}" Width="258" Height="22" />
public ObservableCollection<FeatureLayer> FeatureLayerList
{
get
{
return featureLayerList;
}
set
{
featureLayerList = value;
OnPropertyChanged("FeatureLayerList");
}
}
public FeatureLayer SelectedFeatureLayer
{
get { return selectedFeatureLayer; }
set
{
selectedFeatureLayer = value;
ShapeType.GeometryType = selectedFeatureLayer.ShapeType;
OnPropertyChanged("SelectedFeatureLayer");
OnPropertyChanged("IsEnabledSendButton");
}
}
public ObservableCollection<TextBlock> TextBlocks
{
get
{
textBlocks = new ObservableCollection<TextBlock>() {
new TextBlock { Text="Create...", Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#00A6FF")) } };
return textBlocks;
}
}
private static ObservableCollection<FeatureLayer> featureLayerList;
private ObservableCollection<TextBlock> TextBlocks textBlocks;