UpdateSourceTrigger=PropertyChanged not working until the DataGridTextColumn loses focus?

I’m trying to apply a binding for my datagrid so that I can capture the change to the cells as it happens (as the user types), but for some reason, I can only get to trigger the PropertyChanged event after the cell loses its focus. The same works flawlessly with a regular Textbox, meaning that the OnNameChanged and OnNameChanging events are triggered as soon as the key is down. I was also able to properly make it work with the datagrid by adding a custom column with a Textbox in it, however everything regarding tab navigation among all the cells in the DataGrid became really cumbersome after taking that approach.

Is there a way to make this work using the DataGridTextColumn?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><Grid x:Name="ContentArea">
<TextBox Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<controls:DataGrid AutoGenerateColumns="False" Margin="0,50" ItemsSource="{x:Bind ViewModel.Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<controls:DataGrid.Columns>
<controls:DataGridCheckBoxColumn Header="" Width="40" Binding="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CanUserResize="False"/>
<controls:DataGridTextColumn Header="Parameter" Binding="{Binding Key, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
<controls:DataGridTextColumn Header="Value" Binding="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
<controls:DataGridTextColumn Header="Description" Binding="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
</controls:DataGrid.Columns>
</controls:DataGrid>
</Grid>
</code>
<code><Grid x:Name="ContentArea"> <TextBox Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> <controls:DataGrid AutoGenerateColumns="False" Margin="0,50" ItemsSource="{x:Bind ViewModel.Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <controls:DataGrid.Columns> <controls:DataGridCheckBoxColumn Header="" Width="40" Binding="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CanUserResize="False"/> <controls:DataGridTextColumn Header="Parameter" Binding="{Binding Key, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> <controls:DataGridTextColumn Header="Value" Binding="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> <controls:DataGridTextColumn Header="Description" Binding="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/> </controls:DataGrid.Columns> </controls:DataGrid> </Grid> </code>
<Grid x:Name="ContentArea">
    <TextBox Text="{x:Bind ViewModel.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
    
    <controls:DataGrid AutoGenerateColumns="False" Margin="0,50" ItemsSource="{x:Bind ViewModel.Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <controls:DataGrid.Columns>
            <controls:DataGridCheckBoxColumn Header="" Width="40" Binding="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" CanUserResize="False"/>
            <controls:DataGridTextColumn Header="Parameter" Binding="{Binding Key, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
            <controls:DataGridTextColumn Header="Value" Binding="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
            <controls:DataGridTextColumn Header="Description" Binding="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="*"/>
        </controls:DataGrid.Columns>
    </controls:DataGrid>
</Grid>
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>using App1.Helpers;
using Windows.UI.ViewManagement;
using App1.ViewModels;
namespace App1;
public sealed partial class MainWindow : WindowEx
{
public MainViewModel? ViewModel { get; }
private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue;
private UISettings settings;
public MainWindow()
{
InitializeComponent();
AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
Content = null;
Title = "AppDisplayName".GetLocalized();
// Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
settings = new UISettings();
settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event
ViewModel = App.GetService<MainViewModel>();
}
// this handles updating the caption button colors correctly when indows system theme is changed
// while the app is open
private void Settings_ColorValuesChanged(UISettings sender, object args)
{
// This calls comes off-thread, hence we will need to dispatch it to current app's thread
dispatcherQueue.TryEnqueue(() =>
{
TitleBarHelper.ApplySystemThemeToCaptionButtons();
});
}
}
</code>
<code>using App1.Helpers; using Windows.UI.ViewManagement; using App1.ViewModels; namespace App1; public sealed partial class MainWindow : WindowEx { public MainViewModel? ViewModel { get; } private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue; private UISettings settings; public MainWindow() { InitializeComponent(); AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico")); Content = null; Title = "AppDisplayName".GetLocalized(); // Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239 dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); settings = new UISettings(); settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event ViewModel = App.GetService<MainViewModel>(); } // this handles updating the caption button colors correctly when indows system theme is changed // while the app is open private void Settings_ColorValuesChanged(UISettings sender, object args) { // This calls comes off-thread, hence we will need to dispatch it to current app's thread dispatcherQueue.TryEnqueue(() => { TitleBarHelper.ApplySystemThemeToCaptionButtons(); }); } } </code>
using App1.Helpers;
using Windows.UI.ViewManagement;
using App1.ViewModels;
namespace App1;

public sealed partial class MainWindow : WindowEx
{
public MainViewModel? ViewModel { get; }
private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue;
private UISettings settings;

public MainWindow()
{
    InitializeComponent();

    AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
    Content = null;
    Title = "AppDisplayName".GetLocalized();

    // Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
    dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
    settings = new UISettings();
    settings.ColorValuesChanged += Settings_ColorValuesChanged; // cannot use FrameworkElement.ActualThemeChanged event

    ViewModel = App.GetService<MainViewModel>();
}

// this handles updating the caption button colors correctly when indows system theme is changed
// while the app is open
private void Settings_ColorValuesChanged(UISettings sender, object args)
{
    // This calls comes off-thread, hence we will need to dispatch it to current app's thread
    dispatcherQueue.TryEnqueue(() =>
    {
        TitleBarHelper.ApplySystemThemeToCaptionButtons();
    });
}
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace App1.ViewModels;
public partial class MainViewModel : ObservableRecipient
{
[ObservableProperty]
public string name;
[ObservableProperty]
public ObservableCollection<ParameterViewModel> parameters;
public MainViewModel()
{
Parameters = new ObservableCollection<ParameterViewModel>();
var Parameter = new ParameterViewModel() { Key = "", Value = "", Description = ""};
Parameter.PropertyChanged += Parameter_PropertyChanged;
Parameter.PropertyChanging += Parameter_PropertyChanging;
Parameters.Add(Parameter);
}
partial void OnNameChanged(string value)
{
}
partial void OnNameChanging(string value)
{
}
private void Parameter_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
}
private void Parameter_PropertyChanging(object? sender, PropertyChangingEventArgs e)
{
}
}
public partial class ParameterViewModel : ObservableRecipient
{
[ObservableProperty]
public string key;
[ObservableProperty]
public string value;
[ObservableProperty]
public string description;
}
</code>
<code>using System.Collections.ObjectModel; using System.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel; namespace App1.ViewModels; public partial class MainViewModel : ObservableRecipient { [ObservableProperty] public string name; [ObservableProperty] public ObservableCollection<ParameterViewModel> parameters; public MainViewModel() { Parameters = new ObservableCollection<ParameterViewModel>(); var Parameter = new ParameterViewModel() { Key = "", Value = "", Description = ""}; Parameter.PropertyChanged += Parameter_PropertyChanged; Parameter.PropertyChanging += Parameter_PropertyChanging; Parameters.Add(Parameter); } partial void OnNameChanged(string value) { } partial void OnNameChanging(string value) { } private void Parameter_PropertyChanged(object? sender, PropertyChangedEventArgs e) { } private void Parameter_PropertyChanging(object? sender, PropertyChangingEventArgs e) { } } public partial class ParameterViewModel : ObservableRecipient { [ObservableProperty] public string key; [ObservableProperty] public string value; [ObservableProperty] public string description; } </code>
using System.Collections.ObjectModel;
using System.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;

namespace App1.ViewModels;

public partial class MainViewModel : ObservableRecipient
{
[ObservableProperty]
public string name;

[ObservableProperty]
public ObservableCollection<ParameterViewModel> parameters;

public MainViewModel()
{
    Parameters = new ObservableCollection<ParameterViewModel>();
    var Parameter = new ParameterViewModel() { Key = "", Value = "", Description = ""};
    Parameter.PropertyChanged += Parameter_PropertyChanged;
    Parameter.PropertyChanging += Parameter_PropertyChanging;
    Parameters.Add(Parameter);
}

partial void OnNameChanged(string value)
{

}

partial void OnNameChanging(string value)
{

}

private void Parameter_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{


}

private void Parameter_PropertyChanging(object? sender, PropertyChangingEventArgs e)
{


}    
}
public partial class ParameterViewModel : ObservableRecipient
{
[ObservableProperty]
public string key;
[ObservableProperty]
public string value;
[ObservableProperty]
public string description;
}

I tried setting up the PropertyChanged event for each Parameter added to the ObservableCollection within the MainViewModel, along with implementing the OnKeyChanged event within the ParameterViewModel, the result was the same.

New contributor

c4rlosmarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật