Posts

Showing posts from 2015

talkray Apps Chating In Market

Image

Two-Way Databinding in WPF

As the name suggests, if either one of the property changes the other one automatically updates it. In WPF, this is done using simple design time settings. This is achieved as follows Use the System.Windows.Data.Binding mark-up extension : Set the Mode attribute to System.Windows.Data.BindingMode.TwoWay Use UpdateSourceTrigger attribute to specify when the binding source should be updated. Set this value to "PropertyChanged".This updates the binding source immediately whenever the binding target property changes. This is best explained with example below. I have list box with list of colour names in it. I have a Textbox which shows selected Item Text of list box in Text property. Requirement is, textbox Text is in synch with list box selected Item. When you select "red" item in list box - textbox responds With Text and background colour. Similarly, when you type another colour in Textbox, list box shows the relevant item as selected item in list ...

One-Way Data Binding in WPF

Image
Download Files: OneWayDataBinding.zip   Introduction In one-way data binding we fetch data from a data source and display it in a user interface. That's it. So let's do it.  First of all we need to create the data source. Here I have created three properties and one static method and assigned respective values to the properties. Add one class file to the project and provide it the name  Customer.cs. Now it's time to create the user interface (View) that will show the data from the data source. Add the following code to  MainWindow.xaml : Now we have created the data source and user interface but they are disconnected from each other.  I mean we need to connect our UI (View) to the data source for showing the data on the page. Now, I will call the static method  getCustomer()  and assign the value to the  DataContext  object. Add the following line of code to  MainWindow.xaml.cs : DataContext = Customer.getCust...

ICommand and RelayCommand in WPF

To bind a command of a button you need to bind a property that is an implementation of an ICommand. An ICommand  is composed by: event  EventHandler CanExecuteChanged;     bool  CanExecute( object  parameter);     void  Execute( object  parameter);     CanExecuteChanged  is invoked when changes occur that can change whether or not the command can be executed. CanExecute  will determine whether the command can be executed or not. If it returns false the button will be disabled on the interface. Execute  runs the command logic. With a simple implementation of  ICommand  I can create the following: public   class  NormalCommand : ICommand     {          public   event  EventHandler CanExecuteChanged;           ...

Data Binding in WPF

Image
Binding allows you to link a source object to some control. There are the following two types of bindings: One-Way Binding:  Binds a source to the interface. Two-Way Binding:  Binds a source to the interface and back to the source. INotifyPropertyChanged interface allows sources to interact with the interface and update it as the values change. To bind an object or a list to an element you must set the DataContext property. It is possible to bind an object or a list of objects and you can bind one element to another. To customize how bound data will be displayed you can set the DataTemplate from a control. It is possible to set Data Converters to convert the source type to another type. DataContext DataContext is the property that defines the data a control holds. A model is often assigned to the Window's data context on a MVVM pattern. Or:   One-Way Binding Binds the values from the code to the screen, but not from the screen back to the code. A label con...

Entering Decimal Value In WPF TextBox Which is Binding By Double DataType By Without Delay

Double DataType Binding in WPF TextBox And Entering The Decimal Value Without Using Delay Properties of TextBox In WPF. Sample Demo Adding Amount+charges=Total Design With XAML And Class Uses for Properties. XAML: < Grid >         < Border   BorderThickness = "0"   BorderBrush = "#E3E3E3E3" >             < Grid   Background = "#fafafa" >                 < Grid.RowDefinitions >                     < RowDefinition > </ RowDefinition >                     < RowDefinition   > </ RowDefinition >                 ...