首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF DataGridTemplateColumn结合行为

WPF DataGridTemplateColumn结合行为
EN

Stack Overflow用户
提问于 2012-10-23 12:15:31
回答 1查看 2.3K关注 0票数 0

下面有一个DataGridTemplateColumn设置。我的问题是,当我使用combobox更改一行员工时,还会看到其他一些行也会更改值。我认为它与绑定有某种联系,但这是很奇怪的,因为我似乎看不到我的项目源数据文本(任务),而我在芹菜模板中,但我可以在单元模板内。

代码语言:javascript
复制
<UserControl.Resources>
    <CollectionViewSource x:Key="EmployeeViewSource" Source="{Binding Path=Employees}" />
</UserControl.Resources>
     <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=Tasks}">
     <DataGrid.Columns>
        <DataGridTemplateColumn Header="Employee Name">
            <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <ComboBox DisplayMemberPath="Name" ItemsSource="{Binding Source={StaticResource EmployeeViewSource}}" SelectedValue="{Binding Path=EmployeeID}" SelectedValuePath="EmployeeID" />
                </DataTemplate>
            </DataGridTemplateColumn.CellEditingTemplate>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=Employee.Name, Mode=OneWay}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

相关的ViewModel类似于下面的内容:

代码语言:javascript
复制
Class TaskViewModel : ViewModelBase
{
    public ObservableCollection<Task> Tasks { get; private set; }
    Public ObservableCollection<Employee> Employees { get; private set; }

}

任务/雇员模型都是具有某些字段的实体生成的类。

更新:我开始认为这可能与IsSynchronizedWithCurrentItem属性有关。可能所有的组合框都在尝试同步,因为所选的绑定集合当前正在传输。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-23 16:02:02

在跟踪“IsSynchronizedWithCurrentItem”属性的线索之后,答案似乎在于ComboBox。下面是一个更详细的解释:

https://stackoverflow.com/questions/2458420/wpf-combobox-binding

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

https://stackoverflow.com/questions/13030213

复制
相关文章

相似问题

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