© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
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>
 <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
set
my property.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ EF Core setting property with value converter to null
C#CC# / help
3y ago
Access dependency property from a viewmodel WPF
C#CC# / help
2y ago
❔ EF Core: Owned property with converter expression cannot be converted
C#CC# / help
3y ago
✅ File converter library
C#CC# / help
7mo ago