2015-11-13 37 views
0

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

具體我想要的代碼看起來是這樣的: 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在it.And會有類myChildWindow在mynamespace中。此類可以從System.windows.control.childwindow(可能)繼承。

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

如果問題不清楚,請提問更多的問題。我可以對問題進行編輯。

+0

您提供的代碼應該沒問題,除了 matt

+0

是的,先生。但我的問題是我將如何實現myChildWindow? –

+0

'公共類myChildWindow:ChildWindow {公共myChildWindow():base(){}}'應該足以工作。 – matt

回答

1

你需要2件東西。

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

在我看來,就好像你有已經回答了你自己的問題。如上所述,您可以從ChildWindow繼承。但是,之後,你需要做的是在你的Silverlight項目中包含一個帶有這個類的程序集的引用。一旦你這樣做,程序集將被添加到AppManifest中,DLL將被包含在Xap程序包中,並且你將能夠像Xaml一樣引用它。

上面的命名空間是不正確的想法。它應該是:

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

它應該被編譯到名爲「myassembley」的程序集中。但是,如果引用另一個程序集,則不能在Xaml中使用x:Class。

相關問題