当我写:
<UserControl>
<UserControl.DataContext>
<loca:DataBindingDemo></loca:DataBindingDemo>
</UserControl.DataContext>
<TextBox Text="{Binding Path=CurrentTime}" Height="30" Background="Aqua" Margin="133,141,169,140"></TextBox>
</UserControl>
使用 xmlns:loca="clr-namespace:MyClock"
这是正确的,没有问题,但是当我写:
<UserControl DataContext="{Binding Source=clr-namespace:MyClock.DataBindingDemo}">
<!--
<UserControl.DataContext>
<loca:DataBindingDemo></loca:DataBindingDemo>
</UserControl.DataContext>
-->
<TextBox Text="{Binding Path=CurrentTime}" Height="30" Background="Aqua" Margin="133,141,169,140"></TextBox>
</UserControl>
或者
<UserControl DataContext="{Binding Source=StaticResource, Path=clr-namespace:MyClock.DataBindingDemo}">
<!--
<UserControl.DataContext>
<loca:DataBindingDemo></loca:DataBindingDemo>
</UserControl.DataContext>
-->
<TextBox Text="{Binding Path=CurrentTime}" Height="30" Background="Aqua" Margin="133,141,169,140"></TextBox>
</UserControl>
这没用!为什么?
提前致谢。