【问题标题】:C# SilverLight User Control - Custom Panel not presented on the Form (XAML.CS file)C# SilverLight 用户控件 - 表单上未显示自定义面板(XAML.CS 文件)
【发布时间】: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 部分。你应该决定是否要创建ControlPanel,这是一个巨大的区别。所以你派生的这个基类......是Control还是Panel
  • 嗨 Martin 我用 XAML 部分更新了代码。请告诉我是否定义不正确
  • 你能确定为什么没有显示面板吗?正如我所说,当我打开 Debugger 输出时写入输出
  • 两个问题:首先,我可以看到您正在使用名为 W6CustomPanelControlBase 的东西 - 这不是通常使用的标准 UserControl。其次,默认情况下不显示UserControl - 它显示为另一个页面的一部分(因此,另一个 XAML 文件)。你只给了我们一个 XAML 文件,所以有些东西没有加起来。
  • 如果你不提供关于那个神秘的基类W6CustomPanelControlBase的信息,你将不会得到答案。

标签: c# silverlight panel silverlight-5.0


【解决方案1】:

从您提供的 XAML(以及 .cs 代码)中,我可以看到您没有使用典型的 UserControl。相反,您使用的是来自W6.Web.FormEngine.PropertyPanels 的称为W6CustomPanelControlBase 的东西。

那是什么以及它是如何工作的?我不知道。如果不知道它是如何工作的,就很难告诉你你做错了什么。

此外,UserControl 通常会显示为另一个 XAML 的一部分 - Page、另一个 UserControlFrame。您发布的 XAML 代码只是用户控件本身,而不是它的显示方式 - 换句话说 - 问题可能不在于用户控件本身,而在于它的显示方式。

【讨论】:

    猜你喜欢
    • 2015-01-27
    • 1970-01-01
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多