:私のリストボックスのWPFのマウスは、一貫性のないリストボックスの項目テンプレートにバインド
<ListBox x:Name="ListBox" Style="{StaticResource CustomListBox}" ItemsSource="{Binding HandStats}" Height="410" Width="150" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding HoleCards[0].CardParts.Value}" Margin="2"/>
<Image Source="{Binding HoleCards[0].SuitImagePath}" Width="10" Height="10" Margin="2"/>
<TextBlock Text="{Binding HoleCards[1].CardParts.Value}" Margin="2"/>
<Image Source="{Binding HoleCards[1].SuitImagePath}" Width="10" Height="10" Margin="2"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Runs:" Margin="2"/>
<TextBlock Text="{Binding NumberOfRuns}" Margin="2"/>
<TextBlock Text="Players:" Margin="2"/>
<TextBlock Text="{Binding NumberOfPlayers}" Margin="2"/>
</StackPanel>
<StackPanel.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding Path=DataContext.PopulateReport, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding ElementName=ListBox, Path=SelectedItem}"/>
</StackPanel.InputBindings>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
各アイテムのスタックパネル内の任意の場所をクリックすると、アイテムが選択され、コマンドが起動されるのが理想的です。しかし、私の問題は、アイテムの選択とコマンドの実行が正常に機能していないことです。
アイテムは、テキストブロックの間をクリックするか、テキストブロックの右側の空きスペースでのみ選択されますが、コマンドは実行されません。コマンドは最初にアイテムを選択した後にのみ起動し、テキストブロックの1つまたはイメージの1つを再度クリックします。
私は事前:)
外側のスタックパネルと内側のパネルでこれを試しましたが、まだ運がありません。私は今私の問題を別の方法で解決しようとしています。私はこの投稿を私の答えで更新します – rejy11