首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >datagrid列不更新

datagrid列不更新
EN

Stack Overflow用户
提问于 2011-12-15 00:48:00
回答 1查看 730关注 0票数 1

我有一个带有DataGrid的WPF表单。此DG包含一个包含ComboBox的DataGridTemplateColumn。当我单击DG的新行并从Combobox中选择一个值,然后按tab键切换到下一列时,所选值在combobox列中不再可见。

但是,当我按tab键返回时,正确的值显示在组合框中。

在按tab键离开组合框列时,如何保持选定的值显示在该列中?

以下是我的comboxbox专栏xaml:

代码语言:javascript
运行
复制
<DataGridTemplateColumn Header="Type" Width="160">
<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding LocationType.Description, Mode=TwoWay}"/>
    </DataTemplate>
</DataGridTemplateColumn.CellTemplate>

<DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal">
            <ComboBox Name="cboAddrtype"
                      ItemTemplate="{StaticResource dtAddrType}" IsSynchronizedWithCurrentItem="True"
                      ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.LocationTypesObject, Mode=OneTime}"
                      SelectedItem="{Binding Path=SelectedLocationType, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
                      SelectedValue="{Binding Path=LocationTypeKey, Mode=TwoWay}"
                      SelectedValuePath="InternalKey"
                      Width="100" />

        </StackPanel>

    </DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-15 02:31:21

CellTemplate中绑定LocationType.Description,在CellEditingTemplate中绑定SelectedLocationTypeLocationTypeKey。我不确定来自ComboBox的绑定不会以某种方式影响LocationType.Description

此外,SelectedLocationTypeLocationTypeKey不在DataTemplate的上下文中。您应该添加一个Source绑定属性来获取ViewModel。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8508287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档