2017-04-20 25 views
0

ICTの名前付きGoToSheetをControlTemplateのボタンにバインドします。ControlTemplateのWPFボタンのコマンドが全領域で機能しない

<Button Margin="10 10 10 10" Command="{Binding GoToSheet}"> 
    <Button.Template> 
     <ControlTemplate> 
      <DockPanel Width="840"> 
       <Border DockPanel.Dock="Left" BorderBrush="Black" BorderThickness="5"></Border> 
       <Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="2"></Border> 
       <Border DockPanel.Dock="Right" BorderBrush="Black" BorderThickness="2"></Border> 
       <Border DockPanel.Dock="Bottom" BorderBrush="Black" BorderThickness="2"></Border> 
       <DockPanel DockPanel.Dock="Left"> 
        <StackPanel Orientation="Vertical" Margin="20 10 0 10"> 
         <StackPanel Orientation="Horizontal"> 
          <StackPanel Orientation="Vertical" Margin="0 0 0 10"> 
           <TextBlock Text="{Binding Client}" FontSize="30" FontWeight="Bold" MaxWidth="480"></TextBlock> 
           <TextBlock Text="{Binding Lieu}" FontSize="22" MaxWidth="480"></TextBlock> 
          </StackPanel> 
          <Image Height="35" Width="45" Margin="7 3 0 0" VerticalAlignment="Top" Source="/Resource/Image/CHC.png"></Image> 
         </StackPanel> 
         <StackPanel Orientation="Vertical" VerticalAlignment="Bottom" Margin="20 0 0 0"> 
          <TextBlock Text="{Binding MarqueEngin}" FontSize="26" FontWeight="Bold"></TextBlock> 
          <TextBlock Text="{Binding ModeleEngin}" FontSize="19" FontWeight="Bold"></TextBlock> 
         </StackPanel> 
        </StackPanel> 
       </DockPanel> 
       <DockPanel DockPanel.Dock="Right" Margin="0 10 20 10"> 
        <TextBlock DockPanel.Dock="Top" Text="{Binding DateIntervention, StringFormat=dd/MM/yyyy}" FontSize="30" HorizontalAlignment="Right"></TextBlock> 
        <TextBlock DockPanel.Dock="Bottom" Text="{Binding NumeroEngin}" VerticalAlignment="Bottom" FontSize="30" FontWeight="Bold" HorizontalAlignment="Right"></TextBlock> 
       </DockPanel> 
      </DockPanel> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 

コマンドが成功する領域(imageを参照)のみで動作するのはなぜですか? ボタン領域全体でコマンドが機能するソリューションはありますか?

答えて

0

透明な背景は、ボタンの代わりにDockPanelになければなりません。

<Button Margin="10 10 10 10" Command="{Binding GoToSheet}"> 
     <Button.Template> 
      <ControlTemplate> 
       <DockPanel Width="840" Background="Transparent"> 

macieqqqに感謝します。

1

これは、背景が不足しているため(ボタンの背景がNULLのため)発生します。 いくつかの色の背景を設定してください、例えば:ここで

<Button Margin="10 10 10 10" Background="Transparent" Command="{Binding GoToSheet}"> 

は、同様の問題のためのソリューションです:

Mouse event on transparent background

それが役立つはずです。

+0

ボタンに透明な背景と同じ問題があります。 –

関連する問題