如果查看输出窗口,则应该看到绑定异常。
您遇到的问题如下:在用户控件中,您将标签绑定到用户控件的DP
ProtocolNumber,而不是
DataContext,因此您必须在绑定中添加例如元素名称。
<UserControl Name="MainOptionsPanel" x:Class="ExperienceMainControls.MainControls" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="uc" ><Label Height="Auto" Name="numberLabel">Protocol:</Label><Label Content="{Binding Path=ProtocolNumber, ElementName=uc}" Name="protocolNumberLabel"/>(...)</UserControl>编辑:清除一些事情,如果您更改MainWindow中的绑定,您的usercontrol也将起作用。但是您必须使用RelativeSource绑定到MainWindow的DataContext。
<expControl:MainControls ProtocolNumber="{Binding Path=Number, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />


