100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET

Binding Modes and Converters

Understand how BindingMode controls the direction of data flow between target and source, and how IValueConverter lets bindings transform data for display.

Data BindingIntermediate10 min readJul 10, 2026
Analogies

Controlling the Direction of Data Flow

The Mode property on a Binding decides whether changes flow from source to target, target to source, or both. TwoWay is the default for editable controls like TextBox.Text when bound via a style that sets it explicitly, while OneWay is the default for most other dependency properties, meaning the UI reflects the source but user edits (where even possible) never write back. OneTime reads the source once at binding creation and then detaches, which is useful for values that never change, such as a label populated from configuration at startup.

🏏

Cricket analogy: It is like a stadium's giant screen (OneWay) that always shows the live score from the official scoring system but never lets a fan in the stands edit the total, versus a scorer's own handheld device (TwoWay) where entries flow both ways with the central system.

UpdateSourceTrigger

For TwoWay or OneWayToSource bindings, UpdateSourceTrigger decides when the target-to-source write actually happens. The default for TextBox.Text is LostFocus, so the source only updates once the user tabs away or clicks elsewhere; setting UpdateSourceTrigger=PropertyChanged pushes every keystroke to the source immediately, which is useful for live validation feedback but can be costlier if the source setter triggers expensive work like a network call.

🏏

Cricket analogy: It is like a scorer who only finalizes an over's tally when the umpire signals over-complete (LostFocus), versus commentators updating the run count after literally every ball bowled (PropertyChanged).

Transforming Values with IValueConverter

csharp
public class BoolToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        bool flag = value is bool b && b;
        return flag ? Visibility.Visible : Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value is Visibility v && v == Visibility.Visible;
    }
}

// XAML usage:
// <TextBlock Visibility="{Binding IsError, Converter={StaticResource BoolToVisibilityConverter}}"/>

An IValueConverter implements Convert (source-to-target) and ConvertBack (target-to-source), letting a binding bridge a type mismatch or apply display logic without polluting the view model with UI-specific types like Visibility or Brush. Converters are stateless and should avoid side effects because WPF may call Convert repeatedly, including during design-time preview and layout passes, and a converter that isn't a pure function of its input can cause flickering or inconsistent rendering.

🏏

Cricket analogy: It is like a broadcaster's graphics engine converting a raw run-rate number into a color-coded required-run-rate chip (green/red) without changing the underlying scoring data itself.

IValueConverter instances are typically shared as static resources across every binding that uses them, so never store per-binding state on converter instance fields — concurrent or repeated calls from different bindings will corrupt each other's state. Keep Convert/ConvertBack pure functions of their arguments.

  • BindingMode (OneWay, TwoWay, OneWayToSource, OneTime, Default) controls the direction and frequency of data flow between target and source.
  • OneTime reads the source once at binding creation and then stops tracking further changes in either direction.
  • UpdateSourceTrigger governs when TwoWay/OneWayToSource bindings push target changes back to the source (LostFocus, PropertyChanged, Explicit).
  • TextBox.Text defaults to UpdateSourceTrigger=LostFocus; setting PropertyChanged gives live validation feedback at the cost of more frequent writes.
  • IValueConverter.Convert transforms source-to-target values; ConvertBack does the reverse for TwoWay bindings.
  • Converters should be pure and stateless since WPF may invoke them repeatedly, including during design-time and layout.
  • ConverterParameter lets a single shared converter instance behave differently per binding without needing separate converter classes.

Practice what you learned

Was this page helpful?

Topics covered

#NET#WPFWindowsPresentationFoundationStudyNotes#MicrosoftTechnologies#BindingModesAndConverters#Binding#Modes#Converters#Controlling#StudyNotes#SkillVeris