Attached Property在Xaml中,使用Property Element的写法

来源:互联网 发布:网络摄像机远程监控 编辑:程序博客网 时间:2024/06/07 20:22
  <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>
原创粉丝点击