Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:dotnet:wpf:dependency_properties [2011/04/28 09:12] smayr [Example 2] |
swdev:dotnet:wpf:dependency_properties [2013/01/25 09:16] (current) smayr [Example 1] |
||
---|---|---|---|
Line 57: | Line 57: | ||
DependencyObject source, DependencyPropertyChangedEventArgs e) | DependencyObject source, DependencyPropertyChangedEventArgs e) | ||
{ | { | ||
- | bool control = source as bool; | + | Button |
// Put some update logic here... | // Put some update logic here... | ||
- | | + | |
- | if (control == true) | + | if (control.IsCancel |
{ | { | ||
// do something | // do something | ||
Line 99: | Line 99: | ||
// If employee id is greater than 1000 then make it 1000 | // If employee id is greater than 1000 then make it 1000 | ||
- | static void EmpIdCallBack(DependencyObject d, | + | static void EmpIdCallBack(DependencyObject d, DependencyPropertyChangedEventArgs args) |
- | | + | |
{ | { | ||
Employee emp = (Employee)d; | Employee emp = (Employee)d; | ||
Line 182: | Line 181: | ||
C# code: | C# code: | ||
<code csharp> | <code csharp> | ||
- | . . . | + | using System; |
- | public partial class ucActiveInstrument : UserControl | + | using System.Collections.Generic; |
- | { | + | using System.Linq; |
- | # | + | using System.Text; |
- | // | + | using System.Windows; |
- | // SelectedItemIndex | + | using System.Windows.Controls; |
- | // | + | using System.Windows.Data; |
- | // Dependency Property | + | using System.Windows.Documents; |
- | | + | using System.Windows.Input; |
- | | + | using System.Windows.Media; |
- | " | + | using System.Windows.Media.Imaging; |
- | typeof(int), | + | using System.Windows.Navigation; |
- | typeof(ucActiveInstrument), | + | using System.Windows.Shapes; |
- | new FrameworkPropertyMetadata( | + | |
- | new int(), | + | |
- | OnSelectedItemIndexPropertyChanged | + | |
- | ) | + | |
- | ); | + | |
- | // .NET Property Wrapper | + | namespace ACME.Controls |
- | public | + | { |
+ | public | ||
{ | { | ||
- | // Important: Do not add any logic to these properties, because they are only | + | |
- | // called when you set the property from code. If you set the property from XAML | + | |
- | // the SetValue() method is called directly. | + | // SelectedItemIndex |
- | | + | //----------------------------------- |
- | set { SetValue(SelectedItemIndexProperty, | + | |
- | } | + | public static readonly DependencyProperty SelectedItemIndexProperty = |
- | // Alias | + | DependencyProperty.Register( |
- | public | + | " |
- | { | + | typeof(int), |
- | get { return SelectedItemIndex; | + | typeof(ucActiveInstrument), |
- | } | + | new FrameworkPropertyMetadata( |
+ | | ||
+ | | ||
+ | ) | ||
+ | ); | ||
- | | + | |
- | /// < | + | |
- | /// OnPropertyChanged event handler for fitting view model. | + | { |
- | /// </ | + | // Important: Do not add any logic to these properties, because they are only |
- | /// <param name=" | + | // called when you set the property from code. If you set the property from XAML |
- | /// <param name=" | + | // the SetValue() method is called directly. |
- | /// | + | get { return |
- | | + | set { SetValue(SelectedItemIndexProperty, value); } |
- | | + | |
- | DependencyPropertyChangedEventArgs e) | + | // Alias |
- | { | + | public int SelectedItemIdx |
- | | + | { |
- | //DateTime time = (DateTime)e.NewValue; | + | get { return SelectedItemIndex; } |
+ | } | ||
- | // | + | |
- | // Put some update logic here... | + | /// < |
- | // | + | /// OnPropertyChanged event handler for fitting view model. |
- | | + | |
- | | + | /// <param name=" |
- | | + | /// <param name=" |
- | } | + | ///---------------------------------------------------------------------------------------- |
- | #endregion | + | |
+ | DependencyObject source, | ||
+ | DependencyPropertyChangedEventArgs | ||
+ | | ||
+ | ucActiveInstrument | ||
+ | // | ||
- | | + | |
- | /// < | + | // Put some update logic here... |
- | /// Constructor. | + | // |
- | /// </ | + | // |
- | | + | // |
- | | + | |
- | { | + | } |
- | | + | #endregion |
- | } | + | |
- | | + | |
- | /// < | + | /// < |
- | /// SelectionChange event handler for lstOptions. | + | /// Constructor. |
- | /// </ | + | /// </ |
- | /// <param name=" | + | // |
- | /// <param name=" | + | |
- | | + | { |
- | | + | |
- | { | + | } |
- | | + | |
- | } | + | |
+ | // | ||
+ | /// < | ||
+ | /// SelectionChange event handler for lstOptions. | ||
+ | /// </ | ||
+ | /// <param name=" | ||
+ | /// <param name=" | ||
+ | // | ||
+ | private void lstOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) | ||
+ | { | ||
+ | this.SelectedItemIndex = lstOptions.SelectedIndex; | ||
+ | } | ||
+ | |||
+ | } | ||
} | } | ||
</ | </ |