2012-03-25 5 views
3

私は私は私がどのようにthis.Ifそこらのためのリソースディクショナリを使用する必要があり、このlayout.Doを持つように作成したすべての新しいウィンドウをしたい、この他のウィンドウが継承するウィンドウを作成するにはどうすればよいですか?

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

のようなものです窓がありますか?または私はする必要がありますか他の何かをする

これはちょうど概念を把握することです。私は後で画像とlablesを使用します。

答えて

3

ResourceDictionaryで通常定義するControlTemplateを宣言する必要があります。たとえば:

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

をそして、あなたのウィンドウでこのようにそれを使用します:

<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でアプリケーションリソースにこれを追加する必要があります

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

それは私が言いますX:class属性を追加する必要があります – deception1

+0

実際には、イベントを処理するための別のクラスを追加する必要がありますあなたのリソースファイルの – ionden

+0

とStyle = "{StaticResource {x:Type Window}}" はまた、setter.propertyのヌル値でないと言います。 – deception1