【发布时间】:2016-01-16 12:49:49
【问题描述】:
我用一个文本框(名为“字段”)制作了非常简单的 Silver Light 用户控件(自定义面板),我试图在表单中显示自定义面板,但是虽然触发了类并且我可以看到调试信息(“控件Init 2" 和 "Control Load 2" 在 Debug 输出中),但不显示面板和文本框。
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部分。你应该决定是否要创建Control或Panel,这是一个巨大的区别。所以你派生的这个基类......是Control还是Panel? -
嗨 Martin 我用 XAML 部分更新了代码。请告诉我是否定义不正确
-
你能确定为什么没有显示面板吗?正如我所说,当我打开 Debugger 输出时写入输出
-
两个问题:首先,我可以看到您正在使用名为
W6CustomPanelControlBase的东西 - 这不是通常使用的标准UserControl。其次,默认情况下不显示UserControl- 它显示为另一个页面的一部分(因此,另一个 XAML 文件)。你只给了我们一个 XAML 文件,所以有些东西没有加起来。 -
如果你不提供关于那个神秘的基类
W6CustomPanelControlBase的信息,你将不会得到答案。
标签: c# silverlight panel silverlight-5.0