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

  • Home
  • SEARCH
  • 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 8544485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:34:11+00:00 2026-06-11T12:34:11+00:00

I’ve recently started experimenting with DataBinding and implementing DependencyProperties for my custom classes. It

  • 0

I’ve recently started experimenting with DataBinding and implementing DependencyProperties for my custom classes. It all works fine and the possibilities are exciting, however, I came across a problem that may be only solvable by slightly modifying the overall class design. And I want to make sure this is the only option and I’m not missing anything.

So, my class stores information about video files the user imports into the application. Among other properties, it contains:

public class VideoFile {

    public string FilePath { get; protected set; }
    public uint ID { get; protected set; ]
    public string Extension { get { return Path.GetExtension(FilePath); } }
    public string FileName { get { return Path.GetFilename(FilePath); } }

}

So, I’ve successfully replaced FilePath with an DependencyProperty. However, in the UI, I mostly want to display just the filename, which uses some logic to provide its value. As far as I know, here are my options:

  1. I could simply create DependencyProperties for FileName and Extension, and set their value in the constructor, but that’s redundant; I already have that information in the FilePath, so I want to avoid this option.
  2. Create ValueConverters, one for displaying Filename and one for displaying Extension, and use them in my bindings.

I’ve only met ValueConverters briefly, so I’m not sure about it. Can I use them for this purpose? Or, have I just encountered one of the main reasons they exist? 🙂

And last but not least, can anyone think of a situation similar to this, when a ValueConverter is not the right way to go? I want to avoid jumping straight into them, only to realize it will not work because “that one” property just can’t be expressed in this way.

  • 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-11T12:34:13+00:00Added an answer on June 11, 2026 at 12:34 pm

    Don’t duplicate data.

    Prefer Binding and an IValueConverter, because that way, whenever FilePath changes, Extension and FileName will be updated in the UI as well.

    You could also, of course, raise PropertyChanged for them in FilePath‘s setter but that’s bad practice since FilePath should not have to care about who/what uses it.

    The class then looks like:

    public class VideoFile : INotifyPropertyChanged {
    
        string m_FilePath;
        public string FilePath 
        { 
           get { return m_FilePath; } 
           protected set
           {
              if(value != m_FilePath)
              {
                 m_FilePath = value;
                 RaisePropertyChanged(() => this.FilePath);
              }
           }
        }
        public uint ID { get; protected set; }
    
        #region INotifyPropertyChanged Members
    
        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged<T>(Expression<Func<T>> _PropertyExpression)
        {
            RaisePropertyChanged(PropertySupport.ExtractPropertyName(_PropertyExpression));
        }
    
        protected void RaisePropertyChanged(String _Prop)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(_Prop));
            }
        }
    
        #endregion
    }
    

    Please note that PropertySupport is part of Prism, but you can do without it by calling RaisePropertyChanged("FilePath"), it’s just neat to have type safety because if you change the property’s name you will have a compile-time error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.