private static void OnIconScaleChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MyControl c = (MyControl)d;
if (c != null)
{
double v = (double)e.NewValue;
ScaleTransform scaleTransform = new ScaleTransform(v, v);
c.RenderTransform = scaleTransform;
}
}
public double IconScale
{
get { return (double)GetValue(IconScaleProperty); }
set { SetValue(IconScaleProperty, value); }
}
public static readonly DependencyProperty IconScaleProperty =
DependencyProperty.Register("IconScale", typeof(double), typeof(MyControl), new FrameworkPropertyMetadata(50.0, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnIconScaleChange)));
答案 0 :(得分:1)
在MyControl的构造函数中初始化RenderTransform
:
public MyControl()
{
InitializeComponent();
RenderTransform = new ScaleTransform(IconScale, IconScale);
}