简体   繁体   中英

C# SilverLight User Control - Custom Panel not presented on the Form (XAML.CS file)

I made very simple Silver Light User Control (Custom Panel) with one text box (named "field") and I am trying to present custom panel in the form but although class is triggered and I can see debug information ("Control Init 2" and "Control Load 2" are in Debug output) but panel and textbox are not presented.

XAML.CS file is the following:

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 file has the following: Loaded="LoadTest"

XAML definition is the following:

<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>

From the XAML you presented (as well as from the .cs code) I can see you're not using a typical UserControl . Instead you are using something called a W6CustomPanelControlBase from W6.Web.FormEngine.PropertyPanels .

What that is and how that works? I have no idea. Without knowing how it works it'll be difficult to tell you what you did wrong.

Also - typically a UserControl is displayed as part of another XAML - a Page , another UserControl or a Frame . The XAML code you posted is only the the user control itself, but not how it's shown - in other words - the problem might not lie with the user control itself but with how it's shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM