0

私は Prism(Unity) に初めて真剣に取り組みます。想定されている領域に(適切に)ロードされるツールバーコントロールを備えたモジュールがあります。このツールバーは、ItemsSource データがその ViewModel の ToolButtons プロパティにバインドされたリストボックスであり、3 つの ToolButtons をインスタンス化して ToolButtons コレクションに追加するコンストラクターです。

私の ToolButton クラスには、Title (string)、ButtonFace (Image)、ActiveDocumentCount (int) の 3 つのカスタム DependencyProperties があります。スタイリングは、モジュール内のリソース ディクショナリによって Style と関連付けられた ControlTemplate によって処理されます。プロパティをデータバインドしましたが、TemplateBinding を介して値や画像が表示されません (ただし、スタイル内の他の要素は表示されます)。

データバインディングをデバッグしようとしていますが、役に立ちません。出力ウィンドウに適切なメッセージが表示されず、このブログの 2 番目と 3 番目の提案でも出力が生成されませんでした。詳細な (つまり、PresentationTraceSources.TraceLevel=High) 出力を取得できれば、データバインディングの最前線で何が起こっているかを把握できると思います。

編集:

ツールボタン クラス

public class ToolButton : Button
{
    public ToolButton()
    {
        //DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolButton), new FrameworkPropertyMetadata(typeof(ToolButton)));
    }

    public Image ButtonFace
    {
        get { return (Image)this.GetValue(ButtonFaceProperty); }
        set { this.SetValue(ButtonFaceProperty, value); }
    }
    public static readonly DependencyProperty ButtonFaceProperty =
        DependencyProperty.Register("ButtonFace", typeof(Image), typeof(ToolButton), new PropertyMetadata(null));

    public string Title
    {
        get { return (string)this.GetValue(TitleProperty); }
        set { this.SetValue(TitleProperty, value); }
    }

    public static readonly DependencyProperty TitleProperty =
        DependencyProperty.Register("Title", typeof(string), typeof(ToolButton), new PropertyMetadata(""));

    public int OpenRecordCount
    {
        get { return (int)this.GetValue(OpenRecordCountProperty); }
        set { this.SetValue(OpenRecordCountProperty, value); }
    }

    public static readonly DependencyProperty OpenRecordCountProperty =
        DependencyProperty.Register("OpenRecordCount", typeof(int), typeof(ToolButton), new PropertyMetadata(null));

}
4

1 に答える 1

1

これらの DP は問題ないように見えます CLR でサポートされているプロパティの SetValue は問題ありません....しかし、あなたまたは誰かがそれらのプロパティにローカル値を設定している場合 (たとえば、CLR でサポートされているプロパティまたは DependencyObject.SetValue を呼び出すことによって)、バインディングが破棄されます。

関連リンク:

于 2012-08-01T14:23:28.847 に答える