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 1100487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:53:18+00:00 2026-05-17T00:53:18+00:00

I have a custom converter that has a DefaultText property. All my converter does

  • 0

I have a custom converter that has a DefaultText property. All my converter does is return the DefaultText if the string is null or empty. I can’t seem to get it to work though. Here’s what I’ve got. This is the converter class.

public class DisplayValueConverter : DependencyObject, IValueConverter
{
    public static readonly DependencyProperty DefaultTextProperty = DependencyProperty.Register( "DefaultText",
                                                                                                 typeof ( string ),
                                                                                                 typeof ( DisplayValueConverter ) );

    public string DefaultText
    {
        get { return ( string ) GetValue( DefaultTextProperty ); }
        set { SetValue( DefaultTextProperty, value ); }
    }

    public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
    {

        string empty = ( parameter != null ) ? parameter as string : DefaultText;
        return ( value != null && !string.IsNullOrEmpty( value.ToString().Trim() ) ) ? value.ToString() : empty;
    }

    public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
    {
        return null;
    }
}

And this is my xaml putting it into use.

        <TextBox Grid.Column="1"
                 Grid.Row="3"
                 VerticalAlignment="Center"
                 Margin="0,0,10,0" >
            <TextBox.Text>
                <Binding Path="DataSource.Payee"
                         Mode="TwoWay"
                         NotifyOnSourceUpdated="True"
                         NotifyOnTargetUpdated="True"
                         NotifyOnValidationError="True"
                         ValidatesOnDataErrors="True"
                         UpdateSourceTrigger="PropertyChanged">
                    <Binding.Converter>
                        <k:DisplayValueConverter DefaultText="{Binding ElementName=This, Path=Test, Mode=TwoWay}" />
                    </Binding.Converter>
                    <Binding.ValidationRules>
                        <vr:RequiredField Label="Payee" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

I’ve verified that the DataContext has an object, and that the Path works. So I’m not sure what I’m doing wrong.

  • 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-05-17T00:53:18+00:00Added an answer on May 17, 2026 at 12:53 am

    I think the problem is with your use of Binding.ElementName. Because your value converter isn’t actually part of the visual or logical tree, the binding engine has no way of knowing what tree it needs to traverse in order to find the element with the matching ElementName.

    In this scenario, your best bet is going to be to specifically set the binding’s Source property from code behind, or maybe creating a custom markup extension that would grab the right object for you.

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

Sidebar

Related Questions

I have a custom component, ExportCommandButton, that has two attached properties. This component is
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a few models that need to have custom find conditions placed on
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a custom installer action that updates the PATH environment, and creates an
We have a custom-built Flash-based video player that I maintain, and it needs to
I have an ASP.NET 3.5 SP1 web application that uses a custom JavaScriptConverter. The
I have a class that has two ObservableCollection< TimeValue >'s, where TimeValue is a
I want to hide a Sharepoint web that has been deprecated (via custom means)
I have custom coded several enterprise applications for mid to large organizations to use

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.