简体   繁体   中英

childWindow control in silverlight as a custom control

i know that silverlight already has a child window control , but i want to use this child window control from my own library.

specifically i want the code to look something like this: XAML:

<mycontrols:myChildWindow x:Class="SilverlightClassLibrary1.ChildWindow1"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:mycontrols="clr-namespace:mynamespace;assembly=myassembley"
       Width="400" Height="300" 
       Title="ChildWindow1">
<Grid x:Name="LayoutRoot" Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
    <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
</Grid>

and my project would reference myassembly.dll , which would have mynamespace in it.And there would be class myChildWindow in mynamespace.This class can inherit from System.windows.control.childwindow (possibly).

I know this is a weird implementation way.But i need it to be like this. please tell me how would i implement myChildWindow class?

If the question is not clear ,please ask further questions.i can make the edits in the question.

You need 2 things.

1. Create class derived from ChildWindow

namespace mynamespace
{    
    public class myChildWindow : ChildWindow
    {
        public myChildWindow():base()
        {
            //Add custom constructor code
        }
    }
}

2. In XAML change

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

to

xmlns="http://schemas.microsoft.com/client/2007"

Look at example with XAML body:

<mycontrols:myChildWindow x:Class="Project.Views.EditReport"
           xmlns="http://schemas.microsoft.com/client/2007"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:mycontrols="clr-namespace:mynamespace;assembly=myassembley"
           Width="400"
           Title="Edit Report"></CWindow>

It seems to me as though you have already answered your own question. As mentioned above, you can inherit from ChildWindow. But, after that, what you need to do is include a reference to the assembly with this class in it in your Silverlight project. Once you do that, the assembly will be added to the AppManifest, the DLL will be included in the Xap package, and you will be able to reference it in Xaml as you already have done.

The namespace above is incorrect thought. It should be:

namespace mynamespace
{    
    public class myChildWindow : ChildWindow
    {
        public myChildWindow():base()
        {
            //Add custom constructor code
        }
    }
}

It should be compiled in to the assembly named "myassembley". However, you can't use x:Class in your Xaml if you are referencing another assembly.

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