2013-04-10 1 views
1

내 버튼이 주위에 클릭 할 수없는 클릭 가능 영역을 갖도록 버튼 템플릿을 만들고 싶습니다. 나는 지역을 누를 때 버튼이 이벤트가 여기보이지 않는 클릭 가능 영역이있는 wpf 만들기 버튼 템플릿

내 시도입니다해야 클릭

<Window x:Class="WpfApplication2.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Button Content="Button" HorizontalAlignment="Left" Margin="214,150,0,0" Name="button1" VerticalAlignment="Top" Click="button1_Click"> 
      <Button.Template> 
       <ControlTemplate TargetType="Button"> 
        <Border Background="Pink" Padding="25"> 
         <Button Content="{TemplateBinding Content}"></Button> 
        </Border>  
       </ControlTemplate>    
      </Button.Template> 
     </Button> 
    </Grid> 
</Window> 

내가 경계 내부 누를 때 button1_Click 메소드가 불려가. 하지만 내부 버튼 애니메이션은 활성화되지 않습니다.

테두리 영역 안쪽을 누를 때 클릭 한 것처럼 내부 버튼을 클릭하고 싶습니다.

+0

왜 버튼에 다른 버튼이 포함되어 있습니까? – dowhilefor

+0

@dowhilefor 보이지 않는 클릭 가능한 마진이있는 버튼을 만들 수있는 다른 방법을 사용해도 좋습니다. – Nahum

+1

그건 정상입니다. 내부 버튼은 '클릭 이벤트'를받지 않기 때문에 외부 버튼이 수행합니다. 또한 외부 버튼 인'ControlTemplate'에는 클릭 애니메이션이 없으므로 보이지 않습니다. – DHN

답변

3

모든 명령과 이벤트를 내부 버튼으로 라우팅하는 것과 같은 여러 가지 방법이 있지만 코드 뒤에 많은 작업이 포함될 수 있습니다. 은 "단지 XAML"솔루션이

<ControlTemplate TargetType="Button"> 
    <Border Background="Transparent"> 
     <Border 
      x:Name="Border" 
      Margin="24" 
      CornerRadius="2" 
      BorderThickness="1" 
      Background="{StaticResource NormalBrush}" 
      BorderBrush="{StaticResource NormalBorderBrush}"> 
      <ContentPresenter 
       Margin="2" 
       HorizontalAlignment="Center" 
       VerticalAlignment="Center" 
       RecognizesAccessKey="True"/> 
     </Border> 
    </Border> 
</ControlTemplate> 

처럼 뭔가 전체 Button Template를 복사하고 덮어 쓰기하는 것입니다 그러나 다른 테마에 사용하는 경우이 떨어져 보일 수 있습니다.