1

これはかなり簡単な質問だと思いますが、答えが見つかりません。データ テンプレートに項目テンプレートが定義されています。アイテムが選択されたら、コマンドをトリガーして要素の名前を選択し、それを別の場所に適用したいと思います。しばらくの間、MouseDown イベントは私のコマンドを受け入れません。

<ListView Margin="4" Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Path=ExistingStateInfos, ElementName=Window}"
                  SelectedItem="{Binding Path=SelectedStateInfo, ElementName=Window}" x:Name="statinfoListview">
            <ListView.ItemTemplate>
                <DataTemplate DataType="{x:Type States:StateInfo}">
                    <TextBlock Text="{Binding Path=Name}" MouseDown="{x:Static MyWindow.ApplyStateInfoNameToStateCommand}" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
4

2 に答える 2

0

実際、それは私からでたらめでした、私はただやることを追加します

<TextBlock Text="{Binding Path=Name}" MouseDown="{x:Static ApplyStateInfoNameToState_Click}" />

すいません金曜日です。良い週末を :)

于 2012-10-12T12:57:26.237 に答える
0

コマンドをイベント ハンドラーに直接設定することはできません。

MVVM LightToolkitEventToCommandから使用する

<DataTemplate DataType="{x:Type States:StateInfo}">
    <TextBlock Text="{Binding Path=Name}">
       <i:Interaction.Triggers>
         <i:EventTrigger EventName="MouseDown">
            <Command:EventToCommand Command="{Binding YourCommand, Mode=OneWay}" />
         </i:EventTrigger>
       </i:Interaction.Triggers>
    </TextBlock>
 </DataTemplate>
于 2012-10-12T09:51:19.037 に答える