Question |
Answer |
start learning
|
|
- Extensible Application Markup Language - XAML is text format - same as with any XML where the attributes takes everything as String - XAML takes everything as String Extensible Application Markup Language is actually an XML format which has special schema defined. The tags are very same as with any XML where the attributes takes everything as String. Even though you want to assign a object to a string, you cannot do so because the object can only take a string. Markup Extension allows you to handle these kind of situations. So you can say a Markup extension is actually the way to extend a normal XML to a complete Extensible Markup as XAML. Extensible Applica
|
|
|
start learning
|
|
- Binding is the most important and complex Markup extension which might be used to bind one object. It provides Databound object when the data object is assigned to the DataContext of the object. Thus say you have an object Obj which has several properties like Name, Age etc. Then you might write Text = "{Binding Name}" which means the DataContext object will automatically be evaluated during runtime and the actual value of Name property of the object will be shown on the Text property. Binding has lots of flexibilities, thus you can specify expressions on the databound objects and hence made
|
|
|
start learning
|
|
Binding is actually a Markup Extension. It is a class Binding with few properties. Binding establishes the connection between the application and the business layers
|
|
|
start learning
|
|
we can bind: -two Properties, -One Property and one DependencyProperty, -two DependencyProperties etc. WPF also supports Command Binding.
|
|
|
Binding can be classified into few Types? The types are... start learning
|
|
- DataBinding (most important and primary bindin_ - Object Binding
|
|
|
Object Binding - what enhance this kind of binding? start learning
|
|
objects like: - ObjectDataProvider and - XMLDataProvider, declared into XAML to enhance the capability of object binding
|
|
|
How DataBinding can be achieved? start learning
|
|
by employing either XAML, XAML and C#, and C# itself. So WPF is flexible enough to handle any situation. <TextBox x: Name="txtName" /> ...... <TextBlock Text="{Binding ElementName=txtName, Path=Text. Length}" /> In the above situation, I have shown the most basic usage of Binding. The Text property of TextBlock is bound with the TextBox txtName so that whenever you enter something on the TextBox during runtime, the TextBlock will show the length of the string....... As a Markup Extension binding is actually a Class with properties. Here we specified the value of the property ElementName and Path.
|
|
|
ObjectDataProvider usage to handle data in XAML. start learning
|
|
You can use ObjectDataProvider to handle data in your XAML easily. ObjectDataProvider can be added as Resource and later on can be referenced using StaticResource. <StackPanel Orientation="Vertical"> <StackPanel. Resources> <ObjectDataProvider ObjectType="{x: Type m: StringData}" x: Key="objStrings" MethodName="GetStrings"/> </StackPanel. Resources> <ListBox Name="lstStrings" Width="200" Height="300" ItemsSource="{Binding Source={StaticResource objStrings}}" /> Just as shown above the ObjectType will get a Type, which is the internal class structure for which the Method GetStrings will be called for. From the ListBox, I have referenced the Object using Sta
|
|
|
ObservableCollection - what do? start learning
|
|
ObservableCollection sends automatic notification when a new item is inserted.
|
|
|
INotifyPropertyChanged and INotifyCollectionChanged are needed for what? start learning
|
|
INotifyPropertyChanged and INotifyCollectionChanged are needed to update the UIElement which is bound with the data. So if you are crating a property which needed to update the UI when the value of it is modified, the minimum requirement is to implement the same from INotifyPropertyChanged, and for collection (like ItemsSource), it needs to implement INotifyCollectionChanged. ObservableCollection itself implements INotifyCollectionChanged, so it has support to update the control whenever new item is inserted to the list or any old item is removed from the string.
|
|
|
start learning
|
|
Similar to Object binding, XAML also supports XML binding. You can bind the data coming from XMLDataProvider easily using built in properties like XPath in Binding class definition <TextBlock Text="{Binding XPath=@description}"/> <TextBlock Text="{Binding XPath=text()}"/> So if you are in the node XYZ, the InnerText can be fetched using text() property. The @ sign is used for Attributes. So using XPath you can easily handle your XML.
|
|
|
start learning
|
|
DataContext is actually a Dependency property. It points to Raw Data such that the object that we pass as DataContext will inherit to all its child controls. I mean to say if you define the DataContext for a Grid, then all the elements that are inside the Grid will get the same DataContext. <Grid DataContext="{StaticResource dtItem}"> <TextBox Text="{Binding MyProperty}" /> </Grid> Here as I defined DataContext for the Grid, the TextBox inside the grid can refer to the property MyProperty as the dtItem object will be automatically inherited
|
|
|
start learning
|
|
Source: The source property holds the DataSource. By default it reference the DataContext of the control. If you place Source property for the Binding, it will take that in liew of original DataContext element. ElementName: In case of Binding with another Element, ElementName takes the name of the Element defined within the XAML for reference of the object. ElementName acts as a replacement to Source. If path is not specified for the Binding, it will use ToString to get the data from the Objec Similar to what you might do with XAML, you can also define binding in the codeBehind. To do this you need to use Binding myBinding = new Binding("DataObject"); myBinding. Source = myDataObject; myTextBlock. SetBinding(TextBlock. TextProperty, myBinding);
|
|
|
start learning
|
|
WPF Supports CommandBinding. Each command object like Button exposes a property called Command which takes an object that implements ICommand interface and will execute the method Execute whenever object command gets fired.
|
|
|
What gives the PropertyBinding and CommandBinding? start learning
|
|
The PropertyBinding and CommandBinding gives a total package to separate the presentation logic from the Presentaion Layer. This gives the architecture to put all the logic separated. Microsoft created the whole Expression blend using MVVM pattern which separates the View with the ViewModel and hence gives a chance to handle Unit Testing easily even for presentation layer.
|
|
|
start learning
|
|
In case of MultiBinding the data bound depends on more than one source. You can specify more than one binding expression and on each of them the actual output is dependent on. <TextBlock DockPanel. Dock="Top" > <TextBlock. Text> <MultiBinding Converter="{StaticResource mbindingconv}"> <Binding ElementName="lst" Path="Items. Count" /> <Binding ElementName="txtName" Path="Text" /> <Binding ElementName="txtAge" Path="Text" /> </MultiBinding> </TextBlock. Text> </TextBlock> Here the value for TextBlock is dependent on 3 Elements, the first one is the ListBox count, then txtName and txtAge. I have used Converter to ensure we find all the individual element in the IMultiVal
|
|
|