Binding for non hierarchical object
26/03/2019
Aucun commentaire
If you have an object who is not in herarchical tree, like converter, you cannot bind something even you have define DependyProperty on it.
first you must prepare you converter for having DependencyProperty by override DependencyObject
1 |
public class SelectionConverter : DependencyObject, IMultiValueConverter |
then create DependencyProperties
1 2 3 4 5 6 7 8 9 |
#region Window (DP SHORT) public object Window { get { return (object)GetValue(WindowProperty); } set { SetValue(WindowProperty, value); } } public static readonly DependencyProperty WindowProperty = DependencyProperty.Register("Window", typeof(object), typeof(SelectionConverter), new PropertyMetadata(null)); #endregion #region Name (DP SHORT) public object Name { get { return (object)GetValue(NameProperty); } set { SetValue(NameProperty, value); } } public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(object), typeof(SelectionConverter), new PropertyMetadata(null)); #endregion |
and finally set binding in xaml
as the converter is not in herarchical tree i cannot using binding with ElementName= but i can use x:reference like this
Une erreur s'est produite. Veuillez ré-essayer plus tard. |
Commentaires récents