Home > Net >  Conbobox binding and Property trigger problems
Conbobox binding and Property trigger problems

Time:09-24

Data binding to the combobox, selected property trigger event, how shall we write the

CodePudding user response:

Ask everybody to help, very few points, solve it can help to download resources

CodePudding user response:

The string binding to comcobox, combobox selected items change, the trigger property

CodePudding user response:

Project is urgent, just contact with WPF, thank god

CodePudding user response:

So, I give an example, the code is not much, should be able to help explain what is property change event,
 & lt; Windows x: 
XMLNS="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
XMLNS: x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800" & gt;



 public partial class MainWindow: Window 
{
Public MainWindow ()
{
InitializeComponent();
Var my=new my () {Color="Blue"};
My. PropertyChanged +=delegate {MessageBox. Show (my) Color); };

ComboBox1. ItemsSource=new [] {" Red ", "Green", "Blue", "Yellow", "Cyan", "Magenta"};
ComboBox1. DataContext=my;
}

Public class My: INotifyPropertyChanged
{
The public event PropertyChangedEventHandler PropertyChanged;
Void NotifyPropertyChanged (string propertyName)
{
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (propertyName));
}

String _color;
Public string Color
{
The get {return _color; }
The set {the if (_color! Value)={_color=value; NotifyPropertyChanged (nameof (Color)); }}
}
}
}
  •  Tags:  
  • C#
  • Related