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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:04:19+00:00 2026-06-08T22:04:19+00:00

I am new to WPF and data binding so I could have easily missed

  • 0

I am new to WPF and data binding so I could have easily missed something in my research or I have been am using the wrong search terms (more likely) to find a solution.

The value of a binding seems to be getting passed and not a reference to the object so when the value gets set in the code behind it does not get updated.

In trying to generalize an OpenFileDialog to be useful on some different tabs of a tab control. I created a custom data object that holds the parameters (Path, Filter, and TextBox)

class OpenFileCommandParameters
{
    public string Filter { get; set; }
    public string Path { get; set; }
    public string TextBox { get; set; }
}
class OpenFileCommandParamtersConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        OpenFileCommandParameters parameters = new OpenFileCommandParameters();
        if (values[0] is string) parameters.Filter = (string)values[0];
        if (values[1] is string) parameters.Path = (string)values[1];
        if (values[2] is string) parameters.TextBox = (string)values[2];
        return parameters;
    }
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The XAML for passing the information looks like:

<TextBox Name="ButtonTagImportFileName" Text="{Binding Path=TagImportTabVM.TbFileName}" Height="23" HorizontalAlignment="Left" Margin="83,17,0,0" VerticalAlignment="Top" Width="221" />
<Button Name="TagImportOpenFile" Content="Open File" Command="{Binding Path=OpenFileCommand}" Height="23" HorizontalAlignment="Left" Margin="342,17,0,0" VerticalAlignment="Top" Width="98" >
  <Button.CommandParameter>
      <MultiBinding Converter="{StaticResource openFileCommandParametersConverter}">
          <MultiBinding.Bindings>
              <Binding Source="XML files (*.xml)|*xml|All files (*.*)|*.*"/>
              <Binding Path="AppPath"/>
              <Binding Path="TagImportTabVM.TbFileName"/>
          </MultiBinding.Bindings>
      </MultiBinding>
  </Button.CommandParameter>

Both the textbox and the Open File button have bindings to the same string property.

The property gets updated through the execution of the Command

private void OpenFile(object parameter)
    {
       var parameters = parameter as OpenFileCommandParameters;
       FileDialog.Filter = parameters.Filter;
       FileDialog.InitialDirectory = parameters.Path;
       if (parameters == null) return;
       var result = FileDialog.ShowDialog();
       if (result == true)
       {
           parameters.TextBox = FileDialog.SafeFileName;
       }
    }

Once this command finishes I would expect the value of TbFileName to be the same as what came from the file dialog. This is not the case. as seen from a break point right before the end of the OpenFile block.

enter image description here

I appreciate any assistance you can offer me.

  • 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-08T22:04:22+00:00Added an answer on June 8, 2026 at 10:04 pm

    I was pretty much to the solution, and @a little sheep helped direct me the rest of the way with his solution. Just wanted to fully wrap up the question.

    I was thinking that because the source was not getting updated that I was breaking the binding when I was setting the value through code. This is not the case. It was just simply not knowing that the value had changed so it did not know to update the source.

    Once I discovered this, it was straight forward to find out how to notify the system to let it know it needed to update the source. This gets added to the private void OpenFile(object parameter)

    BindingExpression binding = BindingOperations.GetBindingExpression(parameters.PassedTextBox, TextBox.TextProperty);
    binding.UpdateSource();
    

    Thats all that was added to get it to update properly.

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

Sidebar

Related Questions

I'm new to WPF. I have been been playing around with binding data to
I'm new to WPF data binding. I have a ListBox on a form that
I have a situation where I am using wpf data binding and validation using
I am new to WPF data binding / style / templates... I am trying
I have a scenario which is causing strange behavior with WPF data binding and
I am struggling with the learning curve on WPF data binding and could use
I'm new to WPF and I'm trying to figure out how data binding works,
I'm new to WPF and data binding so hopefully I can explain the problem
I am currently learning WPF (C#) and have taken the following simple data binding
I am using WPF data binding to a dataset to display the contents of

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.