是WPF装饰类有用吗? [英] Is WPF Decorator class useful?

查看:187
本文介绍了是WPF装饰类有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建控件绘制围绕其子边界。所以,我从装饰创建类和派生的:

I need to create control to draw border around its child. So, I have created class and derived it from Decorator:

class RoundedBoxDecorator : Decorator
{
    protected override Size ArrangeOverride(Size arrangeSize)
    {
        //some source
    }

    protected override void OnRender(DrawingContext dc)
    {
        //some source
    }
}

它工作正常,但我对使用装饰的祖先有些疑惑。我发现在MSDN中,有它没有什么特别的方法或属性,只能从它的祖先(UIElement的或FrameworkElement的)得到的。 ArrangeOverride和的OnRender也源于此。

It works fine, but I have some doubts about using Decorator as ancestor. I have found in MSDN that there are no special methods or properties in it, only derived from its ancestors (UIElement or FrameworkElement). ArrangeOverride and OnRender are also derived.

那么,什么装饰类的设计和它有道理使用它?或者,我可以自FrameworkElement派生?

So, what for Decorator class was designed and does it makes sense to use it? Or I can derive from FrameworkElement?

推荐答案

此外它自FrameworkElement继承,在装饰类实现一个孩子的属性(类型的UIElement),以及实现IAddChild接口。因此,装饰是一个可以包含其他元素的最原始的元素。

Besides what it inherits from FrameworkElement, the Decorator class implements a "Child" property (of type UIElement), as well as implementing the IAddChild interface. Thus Decorator is the most primitive element that can contain another element.

你有什么不能够使用边界元素(继承自装饰),以创建一个围绕子元素的边界理由吗?

Is there a reason you were not able to use the "Border" element (which inherits from Decorator) to create the border around the child element?

这篇关于是WPF装饰类有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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