Tutorial by Examples

This example hides the red box (border) if the checkbox is not checked by making use of an IValueConverter. Note: The BooleanToVisibilityConverter used in the example below is a built-in value converter, located in the System.Windows.Controls namespace. XAML: <Window x:Class="StackOverflo...
In order to work with bindings in WPF, you need to define a DataContext. The DataContext tells bindings where to get their data from by default. <Window x:Class="StackOverflowDataBindingExample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&q...
INotifyPropertyChanged is an interface used by binding sources (i.e. the DataContext) to let the user interface or other components know that a property has been changed. WPF automatically updates the UI for you when it sees the PropertyChanged event raised. It is desirable to have this interface im...
You can bind to a property on a named element, but the named element must be in scope. <StackPanel> <CheckBox x:Name="MyCheckBox" IsChecked="True" /> <TextBlock Text="{Binding IsChecked, ElementName=MyCheckBox}" /> </StackPanel>
You can bind to a property of an ancestor in the visual tree by using a RelativeSource binding. The nearest control higher in the visual tree which has the same type or is derived from the type you specify will be used as the binding's source: <Grid Background="Blue"> <Grid ...
The MultiBinding allows binding multiple values to the same property. In the following example multiple values are bound to the Text property of a Textbox and formatted using the StringFormat property. <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}{0}...

Page 1 of 1