Wpf 依赖项属性未更新usercontrol ui

Wpf 依赖项属性未更新usercontrol ui,wpf,silverlight,user-controls,dependency-properties,Wpf,Silverlight,User Controls,Dependency Properties,我有一个usercontrol,上面有几个文本块 <UserControl x:Class="Tester.Messenger" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlfo

我有一个usercontrol,上面有几个文本块

<UserControl x:Class="Tester.Messenger"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         x:Name="myUserControl"
         >  
<TextBlock Text="{Binding ElementName=myUserControl,Path=Header,Mode=TwoWay}" Foreground="LightGray" FontSize="11"  Margin="3,3,0,-3"/>
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ElementName=myUserControl,Path=Message, Mode=TwoWay}" Foreground="White" FontSize="16" Margin="3,-5"/>
当我创建UserControl的对象并更改标头和消息属性并将该控件放置在ItemControls项集合中时,这些不会反映在控件中。控件只显示标题和消息的默认值

 Messenger m = new Messenger();
        m.Header = "colin";
        m.Message = "Download File ?";
        iControl.Items.Add(m);

DependencyProperty.Register的调用中的第一个参数不正确:

public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("HeaderProperty", typeof(string), typeof(UserControl), new PropertyMetadata("header"));
应该是:

public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header", typeof(string), typeof(UserControl), new PropertyMetadata("header"));

字符串应该是属性的名称,因为它将出现在XAML中,即不带“property”后缀。消息
dependencProperty

调用
dependencProperty.Register
中的第一个参数不正确:

public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("HeaderProperty", typeof(string), typeof(UserControl), new PropertyMetadata("header"));
应该是:

public static readonly DependencyProperty HeaderProperty =
        DependencyProperty.Register("Header", typeof(string), typeof(UserControl), new PropertyMetadata("header"));

字符串应该是属性的名称,因为它将出现在XAML中,即不带“property”后缀。当我第一次开始做WPF时,你的消息
DependencyProperty

也是如此-这让我太多次了!是的,非常感谢。犯愚蠢的错误。我看得太久了,想不出来。再次感谢当我第一次开始做WPF的时候——这让我做了太多次了!是的,非常感谢。犯愚蠢的错误。我看得太久了,想不出来。再次感谢