Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何区分鼠标点击与控件的不同部分_C#_Wpf_Templates_Custom Controls_Styles - Fatal编程技术网

C# 如何区分鼠标点击与控件的不同部分

C# 如何区分鼠标点击与控件的不同部分,c#,wpf,templates,custom-controls,styles,C#,Wpf,Templates,Custom Controls,Styles,如果我有一个具有如下模板的控件: <Style x:Key="HomeButtonStyle" TargetType="{x:Type Control}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel VerticalAlignment="Top">

如果我有一个具有如下模板的控件:

 <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_矩形时触发某种事件?那又如何区别于三角部分的点击呢?

哦。。。我明白了。例如:

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