WPF:ComboBox ItemTemplate直到我选中该框后才会应用

问题描述

|| 我有一个ViewModel,它的属性是类的实例。当我说ViewModel时,我有一个ComboBox动态绑定到该类的集合。问题是,如果Item在编辑ItemTemplate之前具有实例,则在我选择并展开ComboBox之前不会被应用。 因此,当我弹出“编辑”窗口时,显示在comboBox中的项目为
myProject.myNameSpace.Type
,但是当我单击ComboBox时,它就会变成应有的
NameOfType SomeInfo
。 XAML:
<ComboBox Grid.Column=\"1\" 
      Width=\"Auto\"
      HorizontalAlignment=\"Left\"
      VerticalAlignment=\"Top\"
      SelectedItem=\"{Binding Path=Type,Mode=TwoWay}\" 
      ItemsSource=\"{Binding Path=AvailableTypes}\"
      TextSearch.TextPath=\"TypeName\"
      IsTextSearchEnabled=\"True\"
      IsEditable=\"True\" >
<ComboBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation=\"Horizontal\">
            <TextBlock Margin=\"4\"
                       Text=\"{Binding Path=TypeName}\" />
            <TextBlock Margin=\"4\"
                       Text=\"{Binding Path=TypeInfo}\" />
        </StackPanel>
    </DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text=\"{Binding Path=Name}\"
                           Foreground=\"Red\">
                </TextBlock>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
    </GroupStyle>
</ComboBox.GroupStyle>
C#:
private ListCollectionView _availableTypes;
public ListCollectionView AvailableTypes
{
    get
    {
        if (_availableTypes == null)
        {
            _availableTypes = new ListCollectionView(Context.GetAllTypes());
            _availableTypes.GroupDescriptions.Add(new PropertyGroupDescription(\"Category\"));
        }
        return _availableTypes;
    }
}

public TypeClass Type
{
    get { return Model.Type; }
    set
    {
        Model.Type = value;
        RaisePropertyChanged(\"Type\");
    }
}
    

解决方法

        无法复制。可能是因为您的AvailableTypes属性返回的是
_availableSections
而不是
_availableTypes
?如果没有,请发布完整的隔离说明。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...