using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Interactivity;
 using System.Linq;
 
 namespace Z.Core.WPF
 {
     /// <summary>
     /// 为对像添加绑定Children的功能
     /// </summary>
     public class BindChildren : Behavior<Panel>
     {
         private static readonly DependencyProperty ChildrenProperty = DependencyProperty.Register("Children", typeof(UIElementCollection), typeof(BindChildren));
 
         public UIElementCollection Children
         {
             get { return (UIElementCollection)GetValue(ChildrenProperty); }
             set { SetValue(ChildrenProperty, value); }
         }
 
         protected override void OnAttached()
         {
             if (Children != null)
             {
                 var children = Children.Cast<UIElement>().ToList();
                 Children.Clear(); // remove all children from original container in order to add it to new container
                 children.ForEach(child => this.AssociatedObject.Children.Add(child));
             }
         }
     }
 
 } 然后在XAML中xmlns:z="clr-namespace:Z.Core.WPF"<Canvas Name="loginCanvas" Grid.Column="1"  Grid.Row="1" Width="500" Height="300" VerticalAlignment="Top" HorizontalAlignment="Center" >
     <i:Interaction.Behaviors>
         <z:BindChildren Children="{Binding CanvasChildren}" />
     </i:Interaction.Behaviors>
 </Canvas>XAML智能提示是可以提示出来的,但是运行报错:
XML 命名空间“clr-namespace:Z.Core.WPF”中不存在标记“BindChildren”。
命名空间“clr-namespace:Z.Core.WPF”中不存在“BindChildren”名称。 谢谢