2017-04-20 40 views
0

我將ICommand命令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。

<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

按鈕上的透明背景存在相同的問題。 –

相關問題