2010-10-19 94 views
0

我有簡單的應用程序。禁用點擊其他控件 - WPF


alt text


<Window x:Class="WpfControlReview.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="120" Width="277" ResizeMode="NoResize"> 
    <Grid> 
     <Button HorizontalAlignment="Stretch" Name="button1" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" Click="button1_Click"> 
     <StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch" Orientation="Vertical"> 
      <Label IsHitTestVisible="False" Content="Select your options and press to commit" Name="label1" HorizontalContentAlignment="Center" FontSize="12" /> 
      <StackPanel Name="stackPanel2" Orientation="Horizontal"> 
       <Expander Header="Color" x:Name="expander1"/> 
       <Expander Header="Make" x:Name="expander2"/> 
       <Expander Header="Payment" x:Name="expander3"/> 
      </StackPanel> 
     </StackPanel> 
     </Button> 
    </Grid> 
</Window> 

private void button1_Click(object sender, System.Windows.RoutedEventArgs e) 
{ 
Application.Current.Shutdown(); 
} 

當我點擊按鈕,應用程序關閉。這就是我想要的。 但是當我點擊其中一個擴展器時,應用程序也會關閉。如何避免這種情況?當用戶點擊三個箭頭中的一個時,我不希望應用程序關閉。

回答

3

嘗試檢查點擊來源(如點擊事件冒泡直到有人明確處理它們)。而且由於按鈕是擴展的父,它會過於接收其click事件(你的意思是把擴展按鈕?):

private void button1_Click(object sender, System.Windows.RoutedEventArgs e) 
{ 
    if (e.Source == this.button1) 
    { 
    Application.Current.Shutdown(); 
    } 
} 
+0

我想expanderto在裏面。按鈕是父項 – Hooch 2010-10-19 13:39:44