举例1
给控件添加一个Behavior
XAML代码
<TextBox x:Name="textbox">
<i:Interaction.Behaviors>
<local:YouBehavior > ※YouBehavior为自定义的行为或Blend3已定义的行为
</i:Interaction.Behaviors>
</TextBox>
C#代码
YouBehavior textbehavior = new YouBehavior ();
Interaction.GetBehaviors(this.textbox).Add(textbehavior);
这段代码可以添加到构筑函数中,或者其他事件中添加。
举例2
XAML代码
<TextBox x:Name="textbox" Grid.Row="1" Grid.Column="1">
C#代码
Grid.SetRow(this.textbox, 1);
Grid.SetColumn(this.textbox, 1);
基本上附件属性本身都提供一个附加到控件的静态方法。