首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF设计器扩展性:如何获得当前设计器缩放值?

WPF设计器扩展性:如何获得当前设计器缩放值?
EN

Stack Overflow用户
提问于 2022-01-24 15:59:04
回答 1查看 46关注 0票数 1

我创建了一个带有设计时支持的简单自定义控件,如描述的这里

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.ComponentModel;

namespace CustomControlLibrary
{
    public class ButtonWithDesignTime : Button
    {
        public ButtonWithDesignTime()
        {
            // The GetIsInDesignMode check and the following design-time 
            // code are optional and shown only for demonstration.
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                Content = "Design mode active";
            }
        }
    }
}

现在我需要知道在设计时设置的缩放因子是什么,但我不知道如何设置。

有什么我可以听的事件来发现这个吗?或者有什么财产可以揭示这一点?

EN

回答 1

Stack Overflow用户

发布于 2022-06-04 01:20:14

我不确定这是否是最优雅的方法,但这是我想出来的。这个问题已经困扰了我很久了!

代码语言:javascript
复制
    private Point GetScaleFactor()
    {
        var rootVisual = PresentationSource.FromVisual(this)?.RootVisual;
        if (rootVisual != null)
        {
            var transformToRoot = TransformToAncestor(rootVisual);
            if (transformToRoot is Transform t)
            {
                return new Point(t.Value.M11, t.Value.M22);
            }
        }

        return new Point(1, 1);
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70836721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档