110 likes | 143 Views
Windows Presentation Foundation (WPF) provides a powerful API with the help of which applications can get input from various devices such as mouse, keyboard, and touch panels. Data binding is the process that establishes a connection between the application UI and business logic.
E N D
Input And Data Binding iFour Consultancy https://www.ifourtechnolab.com/wpf-software-development
Input And Data Binding • Windows Presentation Foundation (WPF) provides a powerful API with the help of which applications can get input from various devices such as mouse, keyboard, and touch panels. • Data binding is the process that establishes a connection between the application UI and business logic. If the binding has the correct settings and the data provides the proper notifications, then, when the data changes its value, the elements that are bound to the data reflect changes automatically https://www.ifourtechnolab.com/wpf-software-development
What We Will Cover • Binding data to UI Elements • Using Converters to convert data during Binding • Using Data Templates to visualize data https://www.ifourtechnolab.com/wpf-software-development
Data Binding Concepts • Binding Components • Target Object • Target Property • Binding Source • Path • Target Property Must be a dependency property https://www.ifourtechnolab.com/wpf-software-development
Binding Modes • OneWay-Updates the target property only when the source property change. • TwoWay-Updates the target property or the property whenever either the target property or the source property changes. • OneWayToSource-updates the source property when the target property changes • OneTime- Updates the target property only when the application starts or when the DataContext undergoes a change. https://www.ifourtechnolab.com/wpf-software-development
What Triggers Updates • Triggering supported by TwoWay or OneWayToSource mode of binding • Dependency property or INotifyPropertyChanged • UpdateSourceTrigger property • Explicit -Updates the binding source only when you call. • UpdateSource- method. • LostFocus-Updates the binding source whenever the binding target element loses https://www.ifourtechnolab.com/wpf-software-development
Data Binding Methods • Binding using XAML • Binding using Code <Label Name="lblNote" Content="{DynamicResource ResourceKey=Note}" /> <TextBox Name="txtNote" VerticalContentAlignment="Top" HorizontalAlignment="Stretch" Text="{Binding AppointmentNote,Mode=TwoWay}" VerticalAlignment="Stretch" Width="Auto" Height="Auto" /> MyData myDataObject = new MyData(DateTime.Now); Binding myBinding = new Binding("MyDataProperty"); myBinding.Source = myDataObject; myText.SetBinding(TextBlock.TextProperty, myBinding); https://www.ifourtechnolab.com/wpf-software-development
Converting DataOverview • Used when data doesn’t match between bindings create a conversion class • When to use • Culture changes needed • Different View of data then native storage • Incompatible data types between target and source https://www.ifourtechnolab.com/wpf-software-development
Converting DataOut-of-Box Converters • Contained in the System.Windows.Controls namespace • BooleanToVisibilityConverter • Converts True/False to Visible, Hidden or Collapsed • BorderGapMaskConverter • Represents a converter that converts the dimensions of a GroupBox control into a VisualBrush https://www.ifourtechnolab.com/wpf-software-development
Data Templates Overview • Makes it easy to put content with data • Easy to define visual styles for data • Reusable and modifiable https://www.ifourtechnolab.com/wpf-software-development