WPF-Designer友好的自定义画布 [英] WPF-Designer-friendly custom canvas

查看:68
本文介绍了WPF-Designer友好的自定义画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个继承Canvas的类,并重写了ArrangeOverride()以基于除Canvas.Left和Canvas.Top

I created a class that inherits Canvas, and overriden ArrangeOverride() to position elements based on some new attached properties in addition to Canvas.Left and Canvas.Top

但是,当我在WPF设计器(Blend或Visual Studio/Cider)中拖动子元素时,它尝试将Canvas.Left和Top设置为在我未实现自定义定位规则的情况下会构成正确位置的值.这导致儿童控制 开始拖动时跳到错误的位置.

However, when I drag child elements in the WPF designer (Blend or Visual Studio / Cider), it attempts to set Canvas.Left and Top to values that would constitute to a correct position have I not implemented custom positioning rules. This leads to child control jumping to an incorrect position the moment I start dragging it.

所以我应该告诉WPF如何将屏幕坐标转换回属性值,但是我该怎么做?

So supposedly I need to tell WPF how to convert onscreen coordinates back to property values, but how do I do that?


我了解如何创建和注册设计时助手组件,并浏览了有关实现自定义装饰器的教程,但是无法找到一种方法来影响设计器的现有内置大小调整/移动装饰器.

I understand how to create and register a design-time helper assembly, and looked through tutorials on implementing custom adorners, but was unable to find a way to influence an existing built-in sizing/moving adorner of the designer.

欢迎提供任何线索,网址,书籍等-我一直在搜索没有结果的几周!

Any clues, urls, books, etc. are welcome -- I've been searching for weeks with no results!

请不要建议使用RenderTransform,它可以工作,但会给设计者带来其他麻烦-但这是另一个问题的主题

Please do not suggest RenderTransform -- it works, but leads to other glitches with the designer -- however that's a topic for another question

推荐答案

您好 Shambler0,

Hi Shambler0,

抱歉,我的回复很晚.

Sorry for my late reply.

>>>"我未实施自定义定位规则,因此定位正确.当我开始拖动它时,这会导致子控件跳到错误的位置."

>>" to a correct position have I not implemented custom positioning rules. This leads to child control jumping to an incorrect position the moment I start dragging it."

据我所知,要建立自己的自定义面板,您需要从 System.Windows.Controls.Panel并实现两个替代:MeasureOverrideLayoutOverride.我们应该知道在创建控件时发生的布局过程,并进而了解布局过程.

As far as I know, to get your own custom panel off the ground, you need to derive from System.Windows.Controls.Panel and implement two overrides: MeasureOverride and LayoutOverride.  we should be aware of the layout process which takes places while creating the controls and in turn to understand the layout process.

所有逻辑都应在后面的代码中实现.

All the logic should be implement in code behind.

在这里,我在codeproject中找到了一篇不错的文章.请看一下.

Here I found a nice article in codeproject. Please take a look.

在WPF中创建自定义面板

最诚挚的问候,

克里斯汀

注意:此回复包含对第三方万维网站点的引用. Microsoft为方便您而提供此信息. Microsoft不控制这些站点,也没有测试在这些站点上找到的任何软件或信息;所以, Microsoft无法对在此找到的任何软件或信息的质量,安全性或适用性做出任何陈述.使用Internet上发现的任何软件都存在固有的危险,Microsoft提醒您确保自己 在从Internet检索任何软件之前,应完全了解风险.

Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


这篇关于WPF-Designer友好的自定义画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆