我有两个关于在 Windows Phone 上开发的问题:
我想创建自定义控件并能够在其中提供一些额外的 XAML。所以我使用ContentControlwith ContentPresenterinside ControlTemplate。
<ContentControl>
    <ControlTemplate>
        <TextBlock Name="TextBlockControl" Text="Existing controls"/>
        <ContentPresenter/>
    </ControlTemplate>
</ContentControl>
它有效,但我无法从代码隐藏TextBlockControl内部访问。总是返回 null。ControlTemplateFindName
其次,我想为 Control 提供属性,所以我像这样创建 DependencyProperty:
public string CustomText
{
    get { return (string)GetValue(CustomTextProperty); }
    set
    {
        SetValue(CustomTextProperty, value);
        TextBlockControl.Text = value;
    }
}
public static readonly DependencyProperty CustomTextProperty =
    DependencyProperty.Register("CustomText", typeof(string), typeof(MyControl), null);
正如你所看到的,我TextBlockControl.Text = value;在我的 Control 中编写了 TextBlock 的文本设置。当我设置静态字符串时 - 它可以工作
<MyControl CustomText="Static Text"/>
但是当我想使用Binding(例如LocalizedStrings资源)时 - 它不起作用。我是否缺少 PropertyMeta 回调或某些 IPropertyChanged 继承?我已经阅读了大量有关相同问题的 StackOverflow 问题,但没有任何内容回答我的问题。