开发者

How to distinguish Mouse.Clicks from different part of a control

If I have a Control with template like开发者_C百科 this:

 <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>

Now, how to fire some sort of event when the PART_Rectangle clicked? And how that would be distinguished from the clicks on PART_Triangle?


Oh... I figured out. for example like that:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜