C
C#3mo 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>
<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
}
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.
0 Replies
No replies yetBe the first to reply to this messageJoin