0

次のカスタム Silverlight ブレッドクラム コントロールがあります。

    <custom:BreadcrumbList Navigator="{Binding ModuleNavigator}">
        <custom:BreadcrumbList.Items>
            <custom:BreadcrumbItem ViewName="Home"/>
            <custom:BreadcrumbItem ViewName="Items"/>
            <custom:BreadcrumbItem Command="{Binding ReturnCommand}"/>
            <custom:BreadcrumbItem ViewName="ItemConstraints"/>
        </custom:BreadcrumbList.Items>
    </custom:BreadcrumbList>

Commandのプロパティを、親コントロールではなくページのデータ コンテキストBreadcrumbItemにバインドしたいと思います。バインド引数を使用して他の XAML 環境でこれを行う方法は知っていますが、ここでは機能しません。Silverlight でこれを行うにはどうすればよいですか?RelativeSource

ありがとう。

4

2 に答える 2

0

データコンテキストのレベルに応じて、いくつかの方法があります。データグリッド自体の要素にバインドしている場合は、親コントロールの型が何であれ、祖先型を持つ相対ソースへのバインディングを使用できます。探しているデータを持つ特定の要素がある場合は、その要素名とデータへのパスを使用してバインドできます。xaml で宣言されたビュー モデルがある場合は、静的リソースにバインドし、ビュー モデルの名前とデータ項目へのパスを使用できます。

于 2013-06-07T21:34:46.067 に答える
0

私は解決策を見つけました。私はまだより良い解決策を待っています。BreadcrumbItem直接サブクラス化しDependencyObjectます。次のプロパティを追加しました。

    private Object _parentContext = null;

    public Object ParentContext
    {
        get { return _parentContext; }
        set { _parentContext = value; RaisePropertyChanged("ParentContext"); }
    }

次にLoaded、(親コントロール) のイベントで、BreadcrumbListすべてのアイテムParentContextプロパティをそのデータ コンテキストに設定します。

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        Loaded -= OnLoaded;

        foreach (var item in Items.OfType<BreadcrumbItem>())
            item.ParentContext = DataContext;
    }

次に、XAML を次のように変更しました。

<custom:BreadcrumbList Navigator="{Binding ModuleNavigator}">
    <custom:BreadcrumbList.Items>
        <custom:BreadcrumbItem ViewName="Home"/>
        <custom:BreadcrumbItem ViewName="Items"/>
        <custom:BreadcrumbItem Command="{Binding ParentContext.ReturnCommand}"/>
        <custom:BreadcrumbItem ViewName="ItemConstraints"/>
    </custom:BreadcrumbList.Items>
</custom:BreadcrumbList>

これは機能しますが、私はまだより良いオプションを探しています。

于 2013-06-07T18:40:29.623 に答える