Search code examples
c#.netwpf

Apply UpdateSourceTrigger=PropertyChanged to all textboxes wpf


How can I write template look like this?

    <DataTemplate ... TextBlock>
    UpdateSourceTrigger=PropertyChanged
    </DataTemplate>

Solution

  • You cannot change the default mode for the UpdateSourceTrigger in a style. This is configured as the DefaultUpdateSourceTrigger of the FrameworkPropertyMetadata class when the DependencyProperty (in this case the Text property) is registered.

    You could either create a custom text box type which derives from TextBox and changes this value when registering the dependency property. Alternatively, you might want to look into the Caliburn.Micro MVVM framework, which automatically sets this for all text boxes in an app (via code, as part of its convention based binding).