The secret sauce behind {binding} in xaml
-
Upload
brendonpage -
Category
Software
-
view
17 -
download
0
Transcript of The secret sauce behind {binding} in xaml
![Page 1: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/1.jpg)
The Secret Sauce Behind {Binding} in XAML
Brendon Page
![Page 2: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/2.jpg)
{Overview}
• What is binding• Why is it difficult• Adding some Context• Behind the scenes
![Page 3: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/3.jpg)
{What Is It}
DataUI
textBox.Text = Value;
Value = textBox.Text;
<TextBox Text="{Binding}" />
• Mechanism for interacting with data.• Display, convert, update data
![Page 4: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/4.jpg)
{Quick Demo}
![Page 5: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/5.jpg)
{Difficult}
• There’s a lot of other things you need to know– DependencyObject /DependencyProperty– INotifyPropertyChanged / INotifyCollectionChanged– IValueConverter
• Cryptic debugging feedback• It’s abstract– MSDN (WPF) Overview
• More than 7500 words• 12 Images• 20 Code blocks
![Page 6: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/6.jpg)
{A lot to know}
![Page 7: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/7.jpg)
• All errors are shown in the output window• When data source is set
– System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''Person' (HashCode=46763000)'. BindingExpression:Path=Name; DataItem='Person' (HashCode=46763000); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String')
• When data source isn’t set–
{Debugging}
![Page 8: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/8.jpg)
{Quick Demo}
![Page 9: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/9.jpg)
{Context}
<Window> <TextBox Text="{Binding Path=Name}" /></Window >
public sealed partial class MainWindow : Window{ public MainPage() { DataContext = new Person { Name = "Brendon" }; }}
XAML
C# DataContextBinding Uses
As it’s default datasource
Cascades down
![Page 10: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/10.jpg)
{Just an Object}
<TextBox Text="{Binding Path=Name}" />
XAML
TextBox textBox = new TextBox();
C#
Binding binding = new Binding("Name");
textBox.SetBinding(TextBox.TextProperty, binding);
textBox.Text = binding;
![Page 11: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/11.jpg)
Design Time
{But Wait There’s More}
Runtime
• Does the work• Read & writes data between
source & target• Subscribes to property changed events• Maintains the relationship
• Describes the binding,Source, Target, DataItem,Path, Mode
![Page 12: The secret sauce behind {binding} in xaml](https://reader036.fdocuments.in/reader036/viewer/2022071907/55cae48abb61eb46788b46ee/html5/thumbnails/12.jpg)
{Conclusion}
• Interact with data• Binding is tricky, until you understand it• Context is important• It’s just an object