0

ここでは、「ChildView」という名前の UserControl があり、「listView」という名前の 1 つの ListView コントロールがあります。この listView の「SelectedItems」プロパティをメイン ウィンドウからコマンド パラメータとしてバインドしようとしていますが、実行されません。関数の実行パラメーターは常に null です。

以下はコードスニペットです。

ChildView 

<UserControl x:Class="MyProj.Views.ChildView"
…………..
    <ListView x:Name="listView" …………..


MainView

…………..
<views:ChildView   x:Name="childView" />
…………..
<Button Command="{Binding ElementName=childView, Path=DataContext.CmdCopyLines}" CommandParameter="{Binding ElementName=childView, Path=DataContext.listView.SelectedItems}" Label="Copy" />
…………..

しかし、それは子供の視点から直接起こっています

ChildView 

<UserControl x:Class="MyProj.Views.ChildView"
…………..
    <ListView x:Name="listView" 
…………..
<Button Command="{Binding CmdCopyLines}" CommandParameter="{Binding ElementName=listView, Path=SelectedItems}" Label="Copy" />
…………..

どんな助けでも大歓迎です

4

1 に答える 1

0

Path=DataContext.listView.SelectedItems は、datacontext が childviewmodel であるため、適切ではありません。

プロパティを childviewmodel に追加し、それを selectedItems にバインドすると、次のことができます。

<Button Command="{Binding ElementName=childView, Path=DataContext.CmdCopyLines}"
        CommandParameter="{Binding ElementName=childView, Path=DataContext.MySelectedItems}" Label="Copy" />
于 2012-04-27T09:51:02.537 に答える