如何区分鼠标。点击控件的不同部分

时间:2010-08-06 19:07:03

标签: c# wpf templates custom-controls styles

如果我有一个带有这样的模板的控件:

 <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的点击次数?

1 个答案:

答案 0 :(得分:0)

哦......我想通了。例如:

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