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.

I appreciate any assistance you can offer me.
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)Thats all that was added to get it to update properly.