[UWP] [XAML] ControlTemplates:我需要重新定义每个属性吗? [英] [UWP][XAML]ControlTemplates: Do I need to redefine every property?

查看:39
本文介绍了[UWP] [XAML] ControlTemplates:我需要重新定义每个属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了几个自定义控件,当然这涉及在XAML中创建ControlTemplate。在ControlTemplate中,显然有很多TemplateBinding。但是,其中大多数都是根网格(宽度,高度,
背景等)。有没有办法避免为这些属性中的每一个添加TemplateBinding?在许多ControlTemplate中,更改只是根网格的子项中的小变化(例如,用椭圆替换矩形),但
几乎所有其他内容都是相同的。看起来需要重新添加每个属性的额外工作(更不用说错误机会)了。有一个更好的方法吗?谢谢。



Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

< blockquote>


一般来说,如果您的自定义控件是从现有控件继承的,则您不需要覆盖所有属性,因为您只需要进行一些小的更改。但是,如果要创建自定义控件而不继承现有控件。你可能需要
来定义这些属性。


祝你好运,


Roy


I have written several Custom Controls, which of course involves creating a ControlTemplate in the XAML. In the ControlTemplate, there are obviously a lot of TemplateBinding(s). However, a majority of these are in things like the root Grid (Width, Height, Background, etc.). Is there any way to avoid adding a TemplateBinding for every one of these properties? In many ControlTemplate(s), the changes are just small changes in the children of the root Grid (for example, replacing a Rectangle with an Ellipse), but almost everything else is the same. It seems like a lot of extra work (not to mention opportunity for error) to need to re-add every property. Is there a better way to do this? Thanks.


Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

解决方案

Hi,

Generally speaking, if your custom control is inherited from an existing control, You don't need to override all the properties as you just want some small changes. But if you are creating a custom control without inheriting from existing controls. You might need to defined these properties.

Best regards,

Roy


这篇关于[UWP] [XAML] ControlTemplates:我需要重新定义每个属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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