How to implement control properties in WPF Applications

By
Hi Friend , Today i will explain about WPF control properties.This is basic part of any WPF Application.In our previous tutorial, I have already explained properties in c#. Here i will explain the control properties of WPF with the help of XAML Language.As you continue to explore WPF , you will see  that  the data binding layer ,animation graphics layers, and many other services are greatly simplified using this new methodologies.
There are various kinds of XAML property syntax .
  1. Dependent Property Syntax
  2. Property element syntax
  3. Attached Property syntax    
1.) Dependent Property Syntax:-
A dependent property allows WPF to compute a particular property's value based on other properties. A dependent property can be implemented to provide self contained validation,default values ,etc.
Example :- 

<Button Name="bnt" FontSize="18" Width="134" Height="29">Proceed</Button>
Description:-
`Here you can see that the content value of the Button is indirectly set as a string data (ex. Proceed) within the <Button> XAML scope.
    We can set this string value to the content property of the control as given below:-

<Button Name="bnt" FontSize="18" Width="134" Height="29" Content="Proceed"/>

Note :- Any property concepts are basically used to make coding(c#,vb,XAML) easy. 

2.) Property Element Syntax:-
we generally know,some properties on a given control require more than simple string data.This property can be set on any Brush type found within the wpf APPs .
Example:- 

<Button Name="bnt" FontSize="18" Width="139" Height="34" Background="Red">Submit Me</Button>
Description :- 
Here you can see that the string value assigned to properties requiring a Brush derived type ()such as Background) map directly to a property on the system.windows.Media.Brushes type.We can use other syntax in which we can pass in start up values to the type.For this we use property element syntax as given below:-

<Button Name="bnt" FontSize="18" Width="139" Height="34" Content="Submit Me">
            <Button.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1.1">
                    <GradientStop Color="Red" Offset="0"/>
                    <GradientStop Color="Yellow" Offset="0.2"/>
                    <GradientStop Color="Green" Offset="0.4"/>
                    <GradientStop Color="Blue" Offset="1"/>
                </LinearGradientBrush>
            </Button.Background>
        </Button>

Output:-

Description : -
Here we are using the <Button.Background> property to specify the look and feel Linear Gradient Brush element

3.)  Attached Property Syntax:-
In Attached property syntax ,child element can store unique values of a property that is actually defined in a parent element.
Example :-

<DockPanel>
  <CheckBox DockPanel.Dock="Left">Remember Me</CheckBox>
 </DockPanel>

Description:-
In above example,tha child element <CheckBox> element is getting the Dock Property of its parent element <DockPanel> . You can easily know the concepts of child and parent element by below c# example.

private void bnt_Click(object sender, RoutedEventArgs e)
        {
            DockPanel my_dock = new DockPanel();
            CheckBox box = new CheckBox();
            box.Content = "Remember Me";
            my_dock.Children.Add(box);
            DockPanel.SetDock(box, Dock.Left);
        }

Note:- 
  • In this c# codes ,the parent type has define a method with a specific signature.
  • You can use above three property concepts in your new wpf application.
For More ...
  1. Namespace in WPF
  2. How to add role based security in asp.net website
  3. How to save and display images from database
  4. How implement login controls in asp.net application
  5. How to implement PLINQ Concepts in asp.net application
  6. Trigger concepts in SQL server
  7. How to run c# program on Notepad easily
  8. How to use WCF services in asp.net

0 comments:

Post a Comment

Powered by Blogger.