Windows Phone での開発について 2 つの質問があります。
カスタム コントロールを作成し、その中に追加の XAML を提供できるようにしたいと考えています。だから私はContentControl
insideContentPresenter
を使いますControlTemplate
。
<ContentControl>
<ControlTemplate>
<TextBlock Name="TextBlockControl" Text="Existing controls"/>
<ContentPresenter/>
</ControlTemplate>
</ContentControl>
うまくいきましたが、分離コードからTextBlockControl
内部にアクセスできません。常に null を返します。ControlTemplate
FindName
次に、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;
、コントロール内の TextBlock にテキストを設定するように記述しています。静的文字列を設定すると動作します
<MyControl CustomText="Static Text"/>
しかし、私が使いたいときBinding
(例えばLocalizedStrings
リソースのために) - それはうまくいきません。PropertyMeta コールバックまたは IPropertyChanged の継承がありませんか? 同じ問題で大量の StackOverflow の質問を読みましたが、質問に対する回答はありませんでした。