C#C
C#2y ago
Elio

Dependency property converter

Hi, i'm using WPF and i wanted to know if there is a way to use dependency property in a converter ? in order to write this kind of line :
 <Grid>
     <Grid.Resources>
         <converter:UnitConverter x:Key="UnitConverter" ObservableUnit="{Binding ObsUnit}"/>
     </Grid.Resources>
 </Grid>

currently i've tried this :
public class UnitConverter : DependencyObject, IValueConverter
{
    #region Properties
    public ObservableUnit ObservableUnit
    {
        get => (ObservableUnit)GetValue(ObservableUnitProperty);
        set => SetValue(ObservableUnitProperty, value);
    }
    #endregion

    #region Fields
    public static readonly DependencyProperty ObservableUnitProperty =
    DependencyProperty.Register("ObservableUnit", typeof(ObservableUnit), typeof(UnitConverter));
    #endregion
}

but it doesn't
set
my property.
Was this page helpful?