[英]How to add WinForm User Control Into WPF so that I can reference it in the xaml.cs file
[英]C# SilverLight User Control - Custom Panel not presented on the Form (XAML.CS file)
我用一个文本框(名为“ field”)制作了非常简单的Silver Light用户控件(“自定义面板”),我试图以表单的形式显示自定义面板,但是尽管触发了类并且我可以看到调试信息(“ Control Init 2”和“控制负载2”在“调试”输出中),但未显示面板和文本框。
XAML.CS文件如下:
namespace CustomPanel2
{
public partial class SilverlightControl1 : W6CustomPanelControlBase
{
public SilverlightControl1()
{
InitializeComponent();
Debug.WriteLine("Control Init 2");
}
private void LoadTest(object sender, RoutedEventArgs e)
{
field.Text = "aaa";
Debug.WriteLine("Control Load 2");
}
}
}
XAML文件具有以下内容: Loaded="LoadTest"
XAML定义如下:
<BaseClass:W6CustomPanelControlBase
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:BaseClass="clr-namespace:W6.Web.FormEngine.PropertyPanels;assembly=W6.Web.FormEngine"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="CustomPanel2.SilverlightControl1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" Loaded="LoadTest">
<Grid x:Name="LayoutRoot" Background="White">
<TextBox x:Name="field" HorizontalAlignment="Left" Height="23" Margin="40,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged" Background="#FF30E6D5" FontWeight="Bold"/>
</Grid>
</BaseClass:W6CustomPanelControlBase>
从您提供的XAML(以及.cs代码),我可以看到您没有使用典型的UserControl
。 相反,您使用的是W6CustomPanelControlBase
的W6.Web.FormEngine.PropertyPanels
。
那是什么以及它如何工作? 我不知道。 如果不知道它是如何工作的,将很难告诉您您做错了什么。
另外-通常,一个UserControl
显示为另一个XAML的一部分-一个Page
,另一个UserControl
或一个Frame
。 您发布的XAML代码只是用户控件本身,而不是用户控件的显示方式-换句话说,问题可能不在于用户控件本身,而在于用户控件的显示方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.