110,534
社区成员
发帖
与我相关
我的任务
分享
public class KDrawingBoard : FrameworkElement, IDisposable
2. 然后在MainWindow的Load事件中写入
kDrawingBoard = new KDrawingBoard();
kDrawingBoard.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
kDrawingBoard.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
this.AddChild(kDrawingBoard);
触发不了KDrawingBoard 的鼠标,键盘事件。
/// <summary>
/// 事件绑定
/// </summary>
/// <param name="eleSrc">绑定源</param>
/// <param name="eleDes">被绑定目标</param>
private void Bind(FrameworkElement eleSrc, FrameworkElement eleDes)
{
try
{
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);
}
catch (System.Exception ex)
{
throw ex;
}
}