WPF:基于void collection更改组合框中的DataTemplate

时间:2016-12-22 18:39:38

标签: c# wpf xaml

我有一个集合ObservableCollection <FeatureLayer> FeatureLayerListObservableCollection <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;

0 个答案:

没有答案