2016-10-31 3 views
1

내가 WPF 프로젝트를 진행하고 발사하지 않고 버튼의 콘텐츠 내부 ToggleSwitch 컨트롤을 클릭하고 나는 다음과 같은 시나리오가 : 나는 내 응용 프로그램 스타일을 MahApps.Metro을 사용하고어떻게 버튼 클릭 이벤트

  • 합니다.
  • 일부 페이지로 이동하는 버튼이 있습니다.
  • 버튼의 내용 안에 ToggleSwitch 컨트롤이 있습니다.

ToggleSwitch를 클릭하여 상태를 변경할 때마다 단추 클릭 이벤트가 발생합니다.

나는 이것을 방지 할 방법이 필요합니다.

enter image description here

<Button x:Name="btn1" Height="40" BorderThickness="0" Width="auto" HorizontalAlignment="Stretch" Margin="0,0,0,0" Style="{DynamicResource SquareButtonStyle}" Click="Button_Click"> 
     <Grid Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> 
      <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="50" /> 
         <ColumnDefinition Width="100" /> 
         <ColumnDefinition Width="*" /> 
         <ColumnDefinition Width="Auto" /> 
      </Grid.ColumnDefinitions> 

      <TextBlock VerticalAlignment="Center" Width="auto" Grid.Column="1">Services</TextBlock> 
      <Controls:ToggleSwitch Grid.Column="3" x:Name="enabledSwitch4" 
            VerticalAlignment="Center" 
            Width="Auto" 
            Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" 
            OnLabel="" OffLabel="" 
            IsChecked="True" HorizontalAlignment="Center" /> 
     </Grid> 
</Button> 
+0

왜 당신은 버튼의 콘텐츠 내부의이 ToggleSwitsch 필요합니까? – punker76

+0

내가 작업하고있는 프로젝트의 디자인은 이것을 필요로합니다. 기본적으로 탐색 사이드 바가 있으며 사용자는 그가 현재있는 페이지에서 일부 서비스를 켜거나 끌 수있는 옵션이 있습니다. – Abdo

+0

토글 버튼으로 버튼 클릭 동작을 활성화/비활성화 하시겠습니까? 아니면 버튼과 토글 스위치의 클릭 이벤트에서 무엇을합니까? – punker76

답변

3
당신이 처리 할 수있는

/버튼의 클릭 이벤트에서이 문제를 방지 할 수 있습니다.

private async void ButtonClick(object sender, RoutedEventArgs e) 
{ 
    if (e.OriginalSource != sender) 
    { 
     // do nothing if clicked the ToggleSwitch 
     e.Handled = true; 
    } 
    else 
    { 
     // handle the button click action 
     await this.ShowMessageAsync(string.Empty, "Yeah, you clicked the real button!"); 
    } 
} 

enter image description here