日期:2014-05-17  浏览次数:20948 次

WPF动态删除控件
我在用WPF做一个图形编辑的程序,通过按钮在画布上动态添加一个自定义的控件,当delete键按下的时候,我想删除我鼠标所在位置的控件。我是这样做的
private void LayoutRoot_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
            UIElement cont1 = sender as UIElement;
           foreach (UIElement child in Canvas1.Children)
         {
                   
              if (child.IsFocused)
              {
                Canvas1.Children.Remove((ContentControl)child);
               }
                 
         }

            
}
达不到我想要的结果,哪位可以给点建议吗?

------解决方案--------------------
这么快???