从ContentControl中编程移动用户控件到另一个 [英] Move a UserControl from a ContentControl to another one programmatically

查看:360
本文介绍了从ContentControl中编程移动用户控件到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个WPF应用程序我想从一个ContentControl中移动用户控件到另一个代码:

In a WPF app I want to move a UserControl from a ContentControl to another one in code:

 myContentControl2.Content = myUserControl;

在这种情况下,我得到一个错误:结果
指定的元素为已经另一个元素的逻辑子。首先断开。

in this case I get an error:
Specified element is already the logical child of another element. Disconnect it first.

在一个的 ControlControl类描述我能看到的 RemoveVisualChild方法,但是当我尝试在代码中使用它,我得到一个未知的方法错误

In a ControlControl class description I can see a RemoveVisualChild method, but when I try to use it in code I get an Unknown method error

myContentControl1.RemoveVisualChild(myUserControl);//here I get an "Unknown method" error

我在哪里错了?结果
如何从ContentControl中移动用户控件到另一个代码隐藏?

推荐答案

设置

myContentControl1.Content = null;

要设置

myContentControl2.Content = myUserControl;



顺便说一句,不与可视化树混淆逻辑树。获取在MSDN WPF 在树的更多信息。

By the way, don't confuse the logical tree with the visual tree. Get more information in Trees in WPF in the MSDN.

这篇关于从ContentControl中编程移动用户控件到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆