问题描述
我在哪里可以找到有关如何刷工作,实现自己的System.Windows.Media.Brush足够的信息?我可以处理所有的冻结行李,但它不是真的很明显我需要重写来得到它的工作。
是啊,所以我不是这个意思,我想用一个predefined刷。我想延长System.Windows.Media.Brush,这是一个抽象类。这一切纯粹是为了我自己的熏陶。我甚至不知道什么样的刷我可以做。我只是想了解如何刷的工作。如下所示:
公共AwesomeBrush:刷
{
保护覆盖可冻结CreateInstanceCore()
{
返回新AwesomeBrush();
}
... //具体刷的东西
}
您无法从 System.Windows.Media.Brush
类继承创建自定义WPF刷,因为类包含抽象成员是内部的。
如果您使用反射来查看 System.Windows.Media.Brush源$ C $ C
类,你会看到下面的内部抽象方法:
内部抽象DUCE.ResourceHandle AddRefOnChannelCore(DUCE.Channel通道);
内部抽象DUCE.Channel GetChannelCore(INT指数);
内部抽象INT GetChannelCountCore();
内部抽象DUCE.ResourceHandle GetHandleCore(DUCE.Channel通道);
内部抽象无效ReleaseOnChannelCore(DUCE.Channel通道);
这些必须重写,但不能因为他们是内部的。
注意:编辑我的答案,因为previous答案是约 System.Drawing.Brush的
和不相关的这个问题。特别感谢米克兰塔宁他的评论。
Where can I find out enough info about how Brushes work to implement my own System.Windows.Media.Brush? I can handle all of the freezable baggage, but it's not really obvious what I need to override to get it to work.
Yeah, so I didn't mean that I want to use a predefined brush. I want to extend System.Windows.Media.Brush, which is an abstract class. This is all purely for my own edification. I'm not even sure what kind of brush I could make. I was just trying to learn how brushes work. As in:
public AwesomeBrush : Brush
{
protected override Freezable CreateInstanceCore()
{
return new AwesomeBrush();
}
... // concrete brush stuff
}
You cannot make a custom WPF brush by inheriting from the System.Windows.Media.Brush
class, because that class contains abstract members that are internal.
If you use Reflector to view the source code of System.Windows.Media.Brush
class, you will see the following internal abstract methods:
internal abstract DUCE.ResourceHandle AddRefOnChannelCore(DUCE.Channel channel);
internal abstract DUCE.Channel GetChannelCore(int index);
internal abstract int GetChannelCountCore();
internal abstract DUCE.ResourceHandle GetHandleCore(DUCE.Channel channel);
internal abstract void ReleaseOnChannelCore(DUCE.Channel channel);
These must be overridden but cannot be because they are internal.
Note: Edited my answer because previous answer was about System.Drawing.Brush
and irrelevant to this question. Special thanks to Mikko Rantanen for his comment.
这篇关于如何实现在WPF自定义画笔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!