I'm trying to create a text preview of a file path by using MultiBinding
in a TextBlock
but I'm having an issue. What I would like to do is to set some values in some UI elements (one combobox and one textbox) and see the preview populating at the bottom of the window.
Preview's XAML
<Label Grid.Row="3" Grid.Column="0" Content="Preview:"/>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="P:\{0}\{1}\file.txt">
<Binding Path="SelectedStudio.Code"/>
<Binding Path="SelectedProject.ProjectCode"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
SelectedStudio and SelectedProject are properties in the ViewModel
ViewModel
public ObservableCollection<WbStudio> Studios { get; set; }
public static WbStudio SelectedStudio { get; set; }
public static WbProject SelectedProject { get; set; }
The objects
public class WbProject
{
public string ProjectName { get; set; }
public string ProjectCode { get; set; }
public string ClientName { get; set; }
public string Address { get; set; }
}
and
public class WbStudio
{
public string Name { get; set; }
public string Code { get; set; }
}
The properties of the ViewModel are bound to a different section of the UI at the top of the window
Setup XAML
<Label Content="Project Studio:"/>
<ComboBox ItemsSource="{Binding Studios, Mode=OneTime}" DisplayMemberPath="Code" SelectedValuePath="Code"
SelectedItem="{Binding SelectedStudio, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Label Content="Project Code:"/>
<TextBox Text="{Binding SelectedProject.ProjectCode}"/>
Here is the issue:
The second Binding element in the Multibinding (<Binding Path="SelectedProject.ProjectCode"/>
) will update and show up in the preview's TextBlock as soon as the TextBox above loses focus (perfect!), while the first Binding element (<Binding Path="SelectedStudio.Code"/>
) never shows in the preview's TextBlock when I select an item from the ComboBox.
What am I missing and how do I fix it?
I thought it was a matter of implementing OnPropertyChanged(string info)
for the WbStudio
properties but that didn't work and WbProject
doesn't have it implemented either so I thought that shouldn't be the issue. I also thought it might have to do with the properties being static
, but they are both static and SelectedProject works. And you don't implement OnPropertyChanged
methods the same way for static properties. So I'm suspecting it has to do with some difference between Combobox
and TextBox
?