如何在silverlight 4中创建ownerdrawn控件?
找不到关于如何在 Silverlight 中创建简单的所有者绘制控件的良好解释。
假设我想创建一个“Arch”或“Line”控件。
我的基类应该是什么?
如何访问绘图上下文以便我的代码可以渲染图形?
我发现 Silverlight 中的 FrameworkElement 在这里没有提供太多帮助。最佳实践是什么?
谢谢
更新:我问这个问题的原因非常简单 - 我正在构建一个虚拟(无限)表面,可以在任何方向上滚动,以显示大量数据的可视化。类似于图表之类的东西。我计划从一些非常简单的东西开始,类似于 Familiy.Show (http://familyshow.codeplex.com/)。该图实现完全是 WPF,并且仅通过 OnRender(DrawingContext) 范例进行渲染。
谢谢
Can't find a good explanation on how to create a simple ownerdrawn control in Silverlight.
Let's say I want to create an "Arch" or a "Line" control.
What should be my base class?
How do I get access to the drawing context so my code can render the graphics?
I see that FrameworkElement in Silverlight doesn't provide much help here. What are the best practices?
Thanks
Update: The reason that I'm asking this is very simple - I'm building a virtual (unlimited) surface that can be scrolled in any direction that should show visualize a lot of data. Something like diagramming. I'm planning to start with something very simple that is similar to the Familiy.Show (http://familyshow.codeplex.com/). That diagram implementation is solely WPF and rendered solely through OnRender(DrawingContext) paradigm.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控件负责在其拥有的矩形表面上绘制像素的概念对于 Silverlight 来说是陌生的。
由于您包含术语“最佳实践”,我将启发式地推断您想要构建完全从原始操作生成 UI 的自定义控件。
创建一个新的“自定义模板控件”。在添加到“themes/generic.xaml”的
ControlTemplate
中,您现在可以包含专门描述您需要的 UI 的 Xaml。Silverlight 支持能够描述从
Shape
派生的基本组件的元素,例如Elipse
(也可以绘制圆弧)、Line
、>矩形
、多边形
和折线
。路径也可用于描述更复杂的形状,其中可能包括贝塞尔曲线段。The concept of a control taking responsibility for drawing pixels on the surface of a rectangle it owns is alien to Silverlight.
Since you include the term "best practice" I'm going to extrapolate heuristically that you want to build custom controls that generate their UI entirely from primitive operations.
Create a new "Custom Templated Control". In the
ControlTemplate
added to the "themes/generic.xaml" you can now include the Xaml that specifically describes UI you need.Silverlight supports elements able to descibe fundemental components that derive from
Shape
such as anElipse
(which can also draw an arc),Line
,Rectangle
,Polygon
andPolyline
. APath
can also be used describe more complex shapes that may includeBezier
segments.