In my WPF+MVVM application I have a View which hosts another usercontrol. The child usercontrol does not follow the MVVM way (because I’m simply hosting a Visio activeX object there), so I’m using the code behind class.
In the View I’m using this code:
<uc:VisioControl Grid.Row="2" x:Name="visioControlUC"
VisioFileName="{Binding ElementName=tbFullFileName,Path=Text, UpdateSourceTrigger=PropertyChanged}"/>
In the same View, I have a Label element where I want to display a field value of a DependencyProperty named SelectedNodeCustomProperties defined on the child user control
<Label x:Name="lbNodeIdValue" DataContext="{Binding ElementName=visioControlUC}" Content="{Binding Path=SelectedNodeCustomProperties.Id, UpdateSourceTrigger=PropertyChanged}"/>
However, this is not working. Running in Debug mode I can see this binding exception in the Output window:
BindingExpression path error: 'visioControlUC' property not found on 'object' ''NSDVizualizerViewModel' (HashCode=65573909)'. BindingExpression:Path=visioControlUC.SelectedNodeCustomProperties.NodeId; DataItem='NSDVizualizerViewModel' (HashCode=65573909); target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
So, why is it that it’s expecting that the child user control be defined in the viewmodel and how can I set the DataContext to the user control when binding the label content?
Thanks,
Adrian
EDIT: To the person who downvoted my question, maybe you can explain why? Is there a similar question on the forum that I haven’t found maybe?
Try