簡體   English   中英

Silverlight中的childWindow控件作為自定義控件

[英]childWindow control in silverlight as a custom control

我知道silverlight已經有一個子窗口控件,但是我想從我自己的庫中使用這個子窗口控件。

特別是我希望代碼看起來像這樣: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>

我的項目將引用myassembly.dll,其中將包含mynamespace.mynamespace中將包含類myChildWindow。此類可以繼承自System.windows.control.childwindow(可能)。

我知道這是一種奇怪的實現方式,但是我需要像這樣。 請告訴我如何實現myChildWindow類?

如果問題不清楚,請提出其他問題。我可以對問題進行修改。

你需要兩件事。

1.創建派生自ChildWindow的類

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

2.在XAML中更改

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

xmlns =“ http://schemas.microsoft.com/client/2007”

查看帶有XAML正文的示例:

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

在我看來,您好像已經回答了自己的問題。 如上所述,您可以從ChildWindow繼承。 但是,在那之后,您需要做的是在Silverlight項目中包含對該類中的程序集的引用。 完成后,該程序集將添加到AppManifest中,該DLL將包含在Xap軟件包中,並且您已經可以在Xaml中引用它。

上面的名稱空間是錯誤的想法。 它應該是:

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

應該將其編譯到名為“ myassemblyy”的程序集中。 但是,如果要引用另一個程序集,則不能在Xaml中使用x:Class。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM