2012-03-25 95 views
3

我有一个窗口,它是这样如何创建其他窗口继承的窗口?

<Window x:Class="pharmacy_Concept.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 

     <Button Content="Login" Height="34" HorizontalAlignment="Left" Margin="12,241,0,0" Name="loginbutton" VerticalAlignment="Top" Width="129" Click="loginbutton_Click" /> 
     <Button Content="Exit" Height="34" HorizontalAlignment="Left" Margin="362,241,0,0" Name="Exitbutton" VerticalAlignment="Top" Width="129" Click="Exitbutton_Click" /> 
    </Grid> 
</Window> 

我想我已经创建了这个layout.Do我必须使用一个资源字典this.If所以如何每一个新的窗口?还是我要做别的事

这只是为了把握这个概念。我将在以后使用图像和标签。

回答

3

你应该声明一个ControlTemplate,你通常在ResourceDictionary中定义。例如:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > 

<Style x:Key="{x:Type Window}" TargetType="{x:Type Window}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Window}"> 
       <Grid Background="Red"> 
        <Button Content="Login" Height="34" HorizontalAlignment="Left" Margin="12,241,0,0" Name="loginbutton" VerticalAlignment="Top" Width="129" Click="loginbutton_Click" /> 
        <Button Content="Exit" Height="34" HorizontalAlignment="Left" Margin="362,241,0,0" Name="Exitbutton" VerticalAlignment="Top" Width="129" Click="Exitbutton_Click" /> 
       </Grid> 

      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

那么你应该在app.xaml添加此应用程序资源:

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Window.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

而在你的窗口中使用了这样的:

Style="{StaticResource {x:Type Window}}" 
+0

它说我应该添加一个X:class属性 – deception1 2012-03-25 06:47:26

+0

确实应该添加另一个类来处理事件在您的资源文件 – ionden 2012-03-25 06:49:40

+0

和Style =“{StaticResource {x:Type Window}}” 也表示必须具有非null值setter.property – deception1 2012-03-25 06:53:20