Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:37:23+00:00 2026-06-02T04:37:23+00:00

How to convert this property to a dependency property ? Regarding that everybody just

  • 0

How to convert this property to a dependency property ? Regarding that everybody just said that “Do not use logic in dependency property” and didn’t proposed a remedy for that :

    public DateTime? SelectedDateGeorgian
    {
        get
        {
           //choose a control based on this "user control" current mode 
           //and return its value
        }


        set
        {
           //choose a control based on this "user control" current mode 
           // and set its property after some manipulations on the value 
        }
    }

I want to convert it to this :

    public static readonly DependencyProperty SelectedDateGeorgianProperty =
    DependencyProperty.Register("SelectedDateGeorgian", typeof(DateTime?), typeof(MyDatePicker), new PropertyMetadata(default(DateTime?)));

    public DateTime? SelectedDateGeorgian
    {
        get
        {
            //Its prohobited to do something here ! So what should I do ?
            //How should I select a control and return its value here ?
            //I can't have a simple backing variable because I should do some conversion here                 

            return (DateTime?)GetValue(SelectedDateGeorgianProperty);
        }
        set
        {
             //I want to convert received value here and 
             // and after that update some UI properties in this user control

            SetValue(SelectedDateMiladiProperty, value);
        }
    }

I want to convert the value which is going to be written in this dependency property and also update UIElements.

And also I want to convert a value from an UIElement and return the converted value whenever it’s going to be read.

So you see that I can’t have a simple backing variable.

Please somebody give me a pattern to implement this.

Thanks for your attention.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:37:25+00:00Added an answer on June 2, 2026 at 4:37 am

    Yes, you can.

    You have to bind your UIElement property to this DependencyProperty and use a Converter. See How to: Convert Bound Data.

    BTW: Here you can find the reason, why DependencyProperties shouldn’t have additional logic in the property wrapper.

    Edit:

    <DatePicker Name="dp1"
                SelectedDate="{Binding Path=SelectedDateGeorgian,
                                       RelativeSource="{RelativeSource AncestorType=UserControl}"}" />
    <DatePicker Name="dp2"
                SelectedDate="{Binding Path=SelectedDateGeorgian,
                                       RelativeSource="{RelativeSource AncestorType=UserControl}",
                                       Converter={StaticResource dateConverter}}" />
    

    create the converter:

    [ValueConversion(typeof(DateTime?), typeof(DateTime?))]
    public class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // your conversions
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // your backconversions
        }
    }
    

    and add it as a resource:

    <src:DateConverter x:Key="dateConverter"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to create one dependency property in a class called "FocusBehaviour" that
I have a node that looks like this, in the xml file: <property name=nameA
I'm trying to use a DateTime? property as a DependencyProperty so that I can
convert this: $300 to this : 300 can't do it with intval() or (int)
I want to convert this linear loop into a concurrent one: for(Item item :
Can anyone help convert this this actionscript to Objective-c? if(mcMain.y >= stage.stageHeight - mcMain.height)
How would I convert this kind of expression in VB.NET? I'm stomped! bool exists=repo.Exists<Post>(x=>x.Title==My
how would you convert this array: Array ( [0] => Array ( [Contact] =>
Is it possible to convert this java code snippet to php? public void testBalanceReturnsToZeroOnVending()
Trying to convert this c code into MIPS and run it in SPIM. int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.