8,756
社区成员




<Control Width="200" Height="200">
<Control.Style>
<Style TargetType="Control">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Control">
<Grid>
<!-- Border -->
<Rectangle Stroke="Red"
StrokeThickness="1"
Margin="4 4 4 4"
StrokeDashArray="4 2" />
<!-- Image -->
<Image Source="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" Margin="5" Stretch="Uniform" />
<!--Ellipses-->
<Ellipse Width="10"
Height="10"
Fill="White"
Stroke="Red"
StrokeThickness="1"
Panel.ZIndex="1"
VerticalAlignment="Top"
HorizontalAlignment="Left" />
<Ellipse Width="10"
Height="10"
Fill="White"
Stroke="Red"
StrokeThickness="1"
Panel.ZIndex="1"
VerticalAlignment="Top"
HorizontalAlignment="Right" />
<Ellipse Width="10"
Height="10"
Fill="White"
Stroke="Red"
StrokeThickness="1"
Panel.ZIndex="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Left" />
<Ellipse Width="10"
Height="10"
Fill="White"
Stroke="Red"
StrokeThickness="1"
Panel.ZIndex="1"
VerticalAlignment="Bottom"
HorizontalAlignment="Right" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Control.Style>
</Control>
using System.Windows;
using System.Windows.Controls;
namespace Antd
{
[TemplatePart(Name = PART_LeftTop, Type = typeof(UIElement))]
[TemplatePart(Name = PART_RightTop, Type = typeof(UIElement))]
public class PhotoFrame : Control
{
#region Fields
private const string PART_LeftTop = "PART_LeftTop";
private const string PART_RightTop = "PART_RightTop";
private UIElement leftTop;
#endregion
static PhotoFrame()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PhotoFrame), new FrameworkPropertyMetadata(typeof(PhotoFrame)));
}
#region Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
leftTop = GetTemplateChild(PART_LeftTop) as UIElement;
SetEvents();
}
private void SetEvents()
{
// 这里为已命名的部件,监听鼠标事件并出来,通常监听事件前要把原事件给清理下。
// 然后为这个控件,定义 Themes,具体样式 就是上面我编写的那个 只不过要给 Ellipse 增加命名,如: x:Name="PART_LeftTop"
}
#endregion
}
}