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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:29:22+00:00 2026-05-15T00:29:22+00:00

I have a window named ParameterEditorView with a ParameterEditorViewModel as DataContext . In the

  • 0

I have a window named ParameterEditorView with a ParameterEditorViewModel as DataContext. In the ParameterEditorViewModel I have a list of ParameterViewModel. In the ParameterEditorView I have an ItemsControl whose ItemsSource is binded to the list of ParameterViewModel in the ParameterEditorViewModel. I need the ParameterViewModel to have a reference to the ParameterView (more on that later). In the Resources section of the ParameterEditorView I add the DataTemplate:

<DataTemplate DataType="{x:Type my:ParameterViewModel}" >
    <my:ParameterView HorizontalAlignment="Left"/> 
</DataTemplate>

So, how can I pass a reference of the ParameterView that is created to show the ParameterViewModel to it?

The reason I need the ParameterView in the ParameterViewModel is the following:
I have a TextBox whose Text property is binded to the PropertyModelView.Name property. But I want to display a default string when the Name is empty or Null. I’ve tried to set the property value to the default string I want when that happens but the TextBox.Text is not set in this scenario. I do something like this:

private string _name;
public string Name
{
    get { return _name; }
    set
    {
        if (value == null || value.Length == 0)
            Name = _defaultName;
        else
            _name = value;
    }
}

I’ve also tried to specifically set the TextBox.Text binding mode to TwoWay without success.
I think this is a defense mechanism to prevent an infinite loop from happening but I don’t know for sure.
Any help on this front would also be highly appreciated.

Thanks,
José Tavares

  • 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-15T00:29:22+00:00Added an answer on May 15, 2026 at 12:29 am

    {Binding } has a FallbackValue, btw.

    Your question, it confuses me. I’d assume your PVM has a collection of PV’s as a public property, which is bound within the UI. Also, I think you’re mixing terms. Its Model-View-ViewModel where the ViewModel is the DataContext of the View, and the Model is exposed by the ViewModel via a public property. Sounds like if you’re binding the window to a collection of ViewModels they are actually Models. It may seem pedantic, but getting your terms correct will help you research and ask questions.

    Another solution would be to add a Converter to your Binding in combination with FallbackValue (I’ve had to do this, IIRC). That converter would be an IValueConverter that returns “DependencyProperty.UnsetValue” if the string is null or empty. I think this works sometimes because the TextBox will set the bound property to the empty string rather than null if the TB is empty. Here’s a little sample to whet your whistle (not guaranteed to work; you need to debug this and tweak it):

    public class ThisMightWorkConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, 
            object parameter, System.Globalization.CultureInfo culture)
        {
            var temp = value as string;
            if(string.IsNullOrWhiteSpace(temp))
                return System.Windows.DependencyProperty.UnsetValue;
            return temp;
        }
    
        public object ConvertBack(object value, Type targetType, 
            object parameter, System.Globalization.CultureInfo culture)
        {
            return value; // you might need to change this
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window with a Gtk Button named openDialog. If I click
I have a window form named form1 and on that I want to show
I have a window .net application named XYZ, I have created a custom folder
I have a file named MMAppDelegate.m: #import MMAppDelegate.h @implementation MMAppDelegate @synthesize window; @synthesize viewController;
I have wpf window named 'GetStarted' with grid which is perent of user control
I have a window named 'winAppt.xaml' and a view model called 'ItemViewModel.vb'. I would
Hello and thanks for your help. I have a window with a stackpanel named
I have an application named ProLaunch.exe. I want to get the active window in
I have a page named addFavorites in my window phone 7 application. It Displays
I have a static HTML page which is named via JavaScript as such: window.name

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.