Iron Python Tools Visual Studio 2010没有提供在IronPython WPF项目中添加WPF用户控件的方法。我该如何创建一个呢?我尝试从C# WPF项目复制粘贴用户控件,但是没有成功。请帮忙解决。
也许不完全符合您的要求,但我想将 UserControl
作为 TabItem
的内容,以保持选项卡的 XAML 文件分离。
在 IronPython 中,我没有找到一个干净的方法,但我找到了一个合理的 hack。我想它对于除 TabItem
以外的组件也可能适用。
首先,我像这样给我的 TabItem
命名:
<TabItem Name="my_tab_item" Header="My Tab Item" />
UserControl
的XAML加载到自定义类中:import wpf
import clr
clr.AddReference("System.Xml")
from System.Windows.Controls import UserControl
class MyUserControl(UserControl):
def __init__(self):
wpf.LoadComponent(self, 'my_user_control.xaml')
然后我像这样将它添加到TabItem
中:
self.FindName("my_tab_item").Content = MyUserControl()