2010-08-06 53 views
0

的不同部分Mouse.Clicks如果我有一個像這樣用模板控制:如何區分控制

<Style x:Key="HomeButtonStyle" TargetType="{x:Type Control}" > 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate> 
       <StackPanel VerticalAlignment="Top"> 
        <Rectangle Width="20" Height="50" x:Name="PART_Rectangle" /> 
        <ed:RegularPolygon x:Name="PART_Triangle" PointCount="3" 
          Height="8" > 
        </ed:RegularPolygon> 
       </StackPanel> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

現在,如何激發某種事件時PART_Rectangle點擊?以及如何將這與PART_Triangle的點擊區分開來?

回答

0

哦......我想通了。例如像這樣:

 private void Control_MouseDown(object sender, MouseButtonEventArgs e) 
    { 
     if(((FrameworkElement)(e.OriginalSource)).Name == "PART_Rectangle") 
     { 
      //RectangleMouseDown 
     } 
    }