样式、行为、模板与自定义控件全解析
1. 样式与行为
在开发用户界面时,样式和行为是非常实用的工具,它们能帮助我们复用用户界面属性设置和代码。
1.1 元素可拖动行为示例
以下代码展示了如何让椭圆元素在画布上可拖动:
<Ellipse Canvas.Left="10" Canvas.Top="70" Fill="Blue" Width="80" Height="60">
<i:Interaction.Behaviors>
<custom:DragInCanvasBehavior></custom:DragInCanvasBehavior>
</i:Interaction.Behaviors>
</Ellipse>
<Ellipse Canvas.Left="80" Canvas.Top="70" Fill="OrangeRed" Width="40" Height="70">
<i:Interaction.Behaviors>
<custom:DragInCanvasBehavior></custom:DragInCanvasBehavior>
</i:Interaction.Behaviors>
</Ellipse>
这个示例通过添加 DragInCanvasBehavior 行为,让椭圆元素可以在画布上被拖动。
超级会员免费看
订阅专栏 解锁全文
13

被折叠的 条评论
为什么被折叠?



