日期:2014-05-17 浏览次数:21230 次
把原始目标元素的属性绑定给目标元素,原始元素改变后,目标元素也改变,这个的FrameworkElement对象是WPF支持的控件
/// <summary>
/// 元素绑定
/// </summary>
/// <param name="eleSrc">原始元素</param>
/// <param name="eleDes">目标元素</param>
/// <remarks>
private void Bind(FrameworkElement eleSrc, FrameworkElement eleDes)
{
Binding oBindWidth = new Binding();
oBindWidth.Source = eleSrc;
oBindWidth.Path = new PropertyPath(FrameworkElement.WidthProperty);
oBindWidth.Mode = BindingMode.TwoWay;
eleDes.SetBinding(FrameworkElement.WidthProperty, oBindWidth);
Binding oBindHgiht = new Binding();
oBindHgiht.Source = eleSrc;
oBindHgiht.Path = new PropertyPath(FrameworkElement.HeightProperty);
oBindHgiht.Mode = BindingMode.TwoWay;
eleDes.SetBinding(FrameworkElement.HeightProperty, oBindHgiht);
}
<UserControl>
<ViewBox Stretch="Uniform">
<圆>
</ViewBox>
</UserControl>