2017-04-07 7 views
1
私は私のデータテンプレートを通じて各項目を表示するカスタムタイプの監視可能なコレクションに結合するリストボックスを持っている

:私のリストボックスの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> 

画像: http://imgur.com/a/QGz8z

各アイテムのスタックパネル内の任意の場所をクリックすると、アイテムが選択され、コマンドが起動されるのが理想的です。しかし、私の問題は、アイテムの選択とコマンドの実行が正常に機能していないことです。

アイテムは、テキストブロックの間をクリックするか、テキストブロックの右側の空きスペースでのみ選択されますが、コマンドは実行されません。コマンドは最初にアイテムを選択した後にのみ起動し、テキストブロックの1つまたはイメージの1つを再度クリックします。

私は事前:)

答えて

0

でのおかげでTransparentStackPanelBackgroundプロパティを設定しようと、私に知らせてくださいあまり意味を作っていないよ場合、私はそうまだWPFに非常に新しいです:

<StackPanel Orientation="Vertical" Background="Transparent"> 
... 

Backgroundがない場合、クリックイベントは期待どおりに発生しません。

+0

外側のスタックパネルと内側のパネルでこれを試しましたが、まだ運がありません。私は今私の問題を別の方法で解決しようとしています。私はこの投稿を私の答えで更新します – rejy11

1

入力バインディングを使用する代わりに、別の方法を使用することにしました。私は自分のVMでプロパティを作成し、これを自分のリストの選択した項目にバインドしました。だから、今は完璧に今働いている新しいアイテムを選択するたびに、プロパティが私のVMで更新されます。シンプル!

関連する問題