- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
按照这2个答案:
Using WPF DataGridComboBoxColumn with MVVM - Binding to Property in ViewModel
Binding a WPF DataGridComboBoxColumn with MVVM
1) 在组合框中进行选择时,我无法设置 ObservableCollections 中的值。
组合框正在使用 ViewModel 中的列表填充,但未设置值。
代码:
<DataGrid ItemsSource="{Binding SidValues1through5, Mode=TwoWay}"
AutoGenerateColumns="False"
Grid.Row="1"
Margin="5"
VerticalAlignment="Top"
HorizontalAlignment="Center">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="1"
Width="100"
SelectedValueBinding="{Binding Value1}"
SelectedValuePath="Value1">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AvailableSids}" />
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AvailableSids}" />
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
public interface ICustomSIDViewModel : IScreen
{
BindableCollection<SidValues> SidValues1through5 { get; set; }
BindableCollection<SidValues> SidValues6through10 { get; set; }
IList<string> AvailableSids { get; }
}
public class SidValues
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public string Value3 { get; set; }
public string Value4 { get; set; }
public string Value5 { get; set; }
}
最佳答案
对于第一个问题 - 它是 WPF,因此您不需要在绑定(bind)上使用 Mode=TwoWay,但为了以防万一,请尝试对初学者使用。
WPF afaik 的默认值是 TwoWay,但不是 SL。还是试试吧。
对于第二个问题,只需在资源字典中声明一个嵌套样式。嵌套样式适用于目标控件的子元素
例如
<Style x:Key="DataGridComboBoxStyle" TargetType="DataGrid">
<!-- Nested -->
<Style.Resources>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AvailableSids}" />
</Style>
</Style.Resources>
</Style>
关于c# - 将 WPF DatagridComboBoxColumns 数据绑定(bind)到 MVVM 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11906115/
您好,我正在使用 WPF DataGrid,并且正在尝试使 ComboBox Column 正常工作。 当我查看网
我正在 WPF 中用 C# 3.5 编写一个应用程序。我想以编程方式将 C# 中的 DataGridComboBoxColumn 添加到 WPF 工具包 DataGrid。问题是控件本身似乎不存在,因
我有一个包含 2 列的数据网格。一列包含角色信息,另一列应该有一个包含可用用户列表的组合框。组合框中的数据与第一列中的数据无关。 组合框没有数据上下文,只有一个项目源,而且我似乎也无法使用绑定(bin
我想知道如何让 DataGridComboBoxColumn 在不处于编辑模式时显示所选项目的文本?是否可以使编辑模式下的组合框最初显示所选项目的文本? 这是我的 XAML:
加载数据网格时是否可以“暴露”WPF 工具包数据网格的 DataGridComboBoxColumn?默认情况下,您必须单击单元格才能显示组合框。我希望用户看到组合框可用,而无需单击单元格。我希望组合
我在 DataGrid 中有一个 DataGridComboBoxColum。我希望能够单击单元格一次并下拉组合框。目前我必须点击多次。
我有一个带有 DatagridComboBoxColumn 的数据网格,我想在用户从 ComboBox 中选择任何东西时触发事件 SelectionChanged,执行一些操作,我该怎么做任何建议,谢
我有一个带有 DataGridComboBoxColumn 的网格,我正在尝试更改单元格的前景色(不处于编辑状态)。 我知道我可以使用 DataGridTemplateColumn 解决这个问题,但我
我在 WPF 和 DataGridComboBoxColumn 中使用 Datagrid。请在下面找到代码: ...
当我单击 DataGridComboBoxColumn 中的单元格时,组合框变得可见,我可以选择项目。当我选择了一个项目时,它在顶部可见。但是,当单元格又名 ComboBox 因为我单击 DataGr
我正在尝试数据绑定(bind) DataGridComboBoxColumn 我在这里做错了什么,因
我正在使用 C#、.NET Framework 4.5.1、MVVM Light 框架和 Entity Framework 6.1.3 开发 WPF。 我有这个DataGrid在一个窗口中:
我有一个 ViewModel(其结构的伪代码): class ViewModel { public List Packages { get; set; } } enum Type {
我有一个 DataGrid,里面有几个 ComboBox 列。使用 ViewModel 中的 IDataErrorInfo 接口(interface)验证这些值。将鼠标悬停在适当的单元格上时,工具提示
我正在尝试将 T 的 ObservableCollection 绑定(bind)到 DataGrid 的 DataGridComboBoxColumn。 DataGrid 定义是:
我目前正在努力使用 C# WPF 中的 DataGridComboBoxColumn。 我有 ToolModel 类 class ToolModel { public long Id { ge
我在 WPF 项目的 DataGrid 中有一个 DataGridComboBoxColumn 设置如下: 但是当我运行该项目时,该列仅显示空白值,并且编辑模式下的组合框执行相同的操作。 DataG
示例代码: class GameListViewModel { private IGameRepository repository; public GameViewModel Gam
我有一个数据网格,在 DataGrid.AutoGeneratingColumn 事件中,我将一些列更改为 DataGridComboBoxColumns。 与此同时,我还想向该新组合框添加一个选择更
我是 WPF 的新手,我遇到了以下情况: class Person{ string Name; List ListAddresses; } 我有一个带有 ItemsSource 的
我是一名优秀的程序员,十分优秀!