Attached Property在Xaml中,使用Property Element的写法
<DockPanel LastChildFill="False"> <TextBox DockPanel.Dock="Bottom">Command: </TextBox> <Button> <Button.Content>Right Button</Button.Content> <DockPanel.Dock>Right</DockPanel.Dock> </Button> </DockPanel>
看到了吗?假如把Attached Property, DockPanel.Dock使用Property Element来设置,而不是通过常规的XML 属性来赋值的话,是直接写在Element内部,并且不用使用Elememt作为前缀的(Button.DockPanel.Dock是错的!)
这也就解释了,Behavior是如何Attach到WPF的Element上的:
<Ellipse Canvas.Left="80" Canvas.Top="70" Fill="OrangeRed" Width="40" Height="70"> <i:Interaction.Behaviors> <custom:DragInCanvasBehavior></custom:DragInCanvasBehavior> </i:Interaction.Behaviors> </Ellipse>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步