Usage of inotifypropertychanged in WPF

Source: Internet
Author: User

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Linq;
Using System.Text;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Data;
Using System.Windows.Documents;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Imaging;
Using System.Windows.Shapes;

Namespace WpfApplication1
{
<summary>
The interactive logic of Window9.xaml
</summary>
public partial class Window9:window
{
Public Window9 ()
{
InitializeComponent ();
This. DataContext = new ViewModel ();
}
}
Class notificationobject:inotifypropertychanged
{
public event PropertyChangedEventHandler PropertyChanged;

public void raisePropertyChanged (String propertyname)
{
if (this. PropertyChanged = null)
{
This. PropertyChanged (This, new PropertyChangedEventArgs (PropertyName));
}
}
}
Class Delegatecommand:icommand
{
A method prototype without return value.
Public action<object> ExecuteCommand = null;
A method prototype return a bool type.
Public Func<object, bool> canexecutecommand = null;
public event EventHandler Canexecutechanged;

public bool CanExecute (object parameter)
{
if (Canexecutecommand! = null)
{
return this. Canexecutecommand (parameter);
}
Else
{
return true;
}
}

public void Execute (object parameter)
{
if (this. ExecuteCommand! = null) this. ExecuteCommand (parameter);
}

public void raisecanexecutechanged ()
{
if (canexecutechanged! = null)
{
Canexecutechanged (this, eventargs.empty);
}
}
}
Class Model:notificationobject
{
private string _wpf = "WPF";

public string WPF
{
get {return _WPF;}
Set
{
_WPF = value;
This. raisePropertyChanged ("WPF");
}
}

public void Copy (object obj)
{
This. WPF + = "WPF";
}

}
Class ViewModel
{
Public Delegatecommand Copycmd {get; set;}
Public model model {get; set;}

Public ViewModel ()
{
This.model = new Model ();
This. Copycmd = new Delegatecommand ();
This. Copycmd.executecommand = new action<object> (this.model.Copy);
}
}

}

________________________________

<window x:class= "Wpfapplication1.window9"
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Title= "Window9" height= "width=" >
<Grid>
<stackpanel verticalalignment= "Top" >
<textblock text= "{Binding model. WPF} "height=" 208 "textwrapping=" Wrapwithoverflow "></TextBlock>
<button command= "{Binding copycmd}" height= "" width= "232" content= "Copy" margin= "30,0"/>
</StackPanel>
</Grid>
</Window>

Usage of inotifypropertychanged in WPF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.