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”名称。 谢谢
解决方案 »
- 如何才能快速读取文本新增的内容
- HttpWebResponse获取ResponseStream乱码的问题
- C#读取二进制流的问题,撒高分求助!
- 窗体间传值,将子窗体设为静态的来接收数据,这样的方法会有什么问题?
- 关于捕获鼠标,键盘的API以及SendMessage()的用法
- 大家帮我看看这段程序是怎样运行的
- 能不能具体解释一下每句是什么意思啊
- 对应于input type="hidden"的ASP.NET控件是什么呢?
- 怎么样让DataGrid中的某一行显示红色呢
- 从vb.net翻译了一个程序到C#,就是过不了,高手帮忙看看。
- 正则啊,为什么用在.net网页里就出错啊,求解啊
- 求助,关于多线程和短时间内更新大量数据的问题
谢谢