wpf - Wpf DataGridComboBoxColumn 绑定在选择数据网格中的另一行后发生
问题描述
我有这个绑定到可观察集合“CessatiTab”的 DataGrid
public DBConnect mDbConnect;
public ObservableCollection<CessatiViewModel> CessatiTab => MCessatiTab;
private ObservableCollection<CessatiViewModel> MCessatiTab { get; set; }
然后这个 observable 集合是这样填充的:
public ObservableCollection<CessatiViewModel> GetTable()
{
mDbConnect = new DBConnect();
var webTab = new DataTable();
webTab = mDbConnect.Cessati();
var obj = new ObservableCollection<CessatiViewModel>();
foreach (DataRow row in webTab.Rows)
{
var test = new CessatiViewModel
{
Id = int.Parse(row[0].ToString()),
Codice_Fiscale = row[1].ToString(),
Stato_Pagatore = row[2].ToString(),
InsertedDate = DateTime.Parse(row[3].ToString()),
Appuntamentodate = row[5] == DBNull.Value
? (DateTime?)null
: DateTime.Parse(row[5].ToString()),
Appuntamentotime = row[6] == DBNull.Value
? (DateTime?)null
: DateTime.Parse(row[6].ToString()),
Operatore = row[7].ToString(),
Esito = row[8].ToString(),
};
obj.Add(test);
}
return obj;
}
最后xaml是这样的:
<DataGrid Margin="20 10 0 50"
x:Name="MainTable"
ItemsSource="{Binding CessatiTab}"
FontSize="12"
MaxHeight="750"
RowHeight="30"
SelectionMode="Single"
Grid.Row="1"
CanUserSortColumns="True"
VerticalAlignment="Top"
HorizontalAlignment="Left"
CanUserAddRows="False"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Hidden"
materialDesign:DataGridAssist.CellPadding="13 0 5 0"
materialDesign:DataGridAssist.ColumnHeaderPadding="5">
<DataGrid.Columns>
<!--Esito Column-->
<materialDesign:MaterialDataGridComboBoxColumn Header="Esito"
SelectedItemBinding="{Binding Esito, Mode=TwoWay}"
ItemsSourceBinding="{Binding DataContext.Esiti, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}"/>
</DataGrid.Columns>
</DataGrid>
一切正常,唯一的问题是组合框列的值的更改仅在我选择另一行时发生,而不是在我更改其中的值时发生。所以我必须选择另一行来进行绑定
private string _esito;
private bool _appuntamento;
private bool _message;
public string Esito
{
get { return _esito; }
set
{
_esito = value;
if(_esito == "Appuntamento" || _esito == "Segreteria")
{
Appuntamento = false;
Message = true;
}
else if(_esito != "Appuntamento" || _esito == "Segreteria")
{
Appuntamento = true;
Message = false;
}
OnPropertyChanged();
}
}
请问有什么帮助吗?
解决方案
尝试将UpdateSourceTrigger
绑定的属性设置为PropertyChanged
:
<materialDesign:MaterialDataGridComboBoxColumn Header="Esito"
SelectedItemBinding="{Binding Esito, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
... />
推荐阅读
- angular - 向 ng-container 添加动画
- html - 在 react-quill 编辑器中直接输入 HTML 标记
- numpy - 如何将 numpy 数组作为逻辑回归的输入?
- php - PHPExcel:某些行在导入时未在我的 .xls 文件中导出,但在我回显输出时显示?
- c# - 如何找出哪个Windows进程正在使用文件?
- javascript - 如何确定同一数组中是否存在重复值?
- php - 如何在 laravel 中为我的购物项目创建 cms 用户类型和常规配置文件
- java - 在 BaseFragment 中使用 dagger2 实例化视图模型
- javascript - 为什么 @ViewChild(NgbDropdown) 在我的组件中不起作用?
- amazon-web-services - 具有 MariaDB 成本的 Amazon RDS