2017-11-06 8 views
0

내가 내 프로젝트에 4 창을 고려하고 나는 윈도우의 객체를 만들 수있는 방법은 특정 닫기 버튼을 하나 개의 제목어떻게 제공 할 수있는 부모 창 - WPF

를 제공하기 위해 노력하고 창 모두로 사용 무늬. 여기

우리가 패턴 창에 대해 가지고있는 예입니다 :

나는 패턴으로 내 창을 모두 사용할 수있는 방법을
<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     WindowStyle="None" AllowsTransparency="True" > 
<Grid> 
<Button Content="Close" Height="40" VerticalAlignment="Top" HorizontalAlignment="Right"/> 
<TextBlock VerticalAlignment="Top" HorizontalAlignment="Center" X:Name="WindowTitle/> 
</Grid> 
</Window> 

. 감사합니다

+0

이게 당신이 찾고 있는게 있나요? https://stackoverflow.com/questions/7174315/understanding-wpf-deriving-window-class – Aaron

+0

@Aaron 괜찮습니다. 고마워요.하지만 패턴에 특정 버튼이 있어야합니까? –

+0

기본 클래스의 단추 텍스트와 기능을 기본 클래스의 속성 (또는 속성)에 바인딩하는 것이 좋습니다. 그런 다음 하위 클래스에서 해당 속성을 설정하면 "OnPropertyChanged"알림은 버튼에 필요한 작업 (다른 핸들러/바인딩 추가, 불필요한 핸들러/바인딩 제거, 텍스트 변경 등)을 수행합니다. 또는 얼마나 미쳐 있어야하는지, 기본 창을 만든 것과 같은 방법으로 '기본 버튼'을 만들 수 있으며, 기본 창과 완전히 견적을 낼 수 있습니다. – Aaron

답변

0

실제로 실제로는 부모 창을 쓸 필요가 없습니다. 대신 StyleTemplate을 사용할 수 있습니다. 더 편리하고 Microsoft WPF 팀에서 권장합니다.

<Application x:Class="Walterlv.Demo.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      .........> 
    <Application.Resources> 
     <Style x:Key="Style.Window.Default" TargetType="Window"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="Window"> 
         <Grid Background="{TemplateBinding Background}"> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="40"/> 
           <RowDefinition/> 
          </Grid.RowDefinitions> 
          <Button Grid.Row="0" Content="Close" Height="40" VerticalAlignment="Top" HorizontalAlignment="Right"/> 
          <TextBlock Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center" 
             Text="{TemplateBinding Title}"/> 
          <Border Grid.Row="1" BorderThickness="{TemplateBinding BorderThickness}" 
            BorderBrush="{TemplateBinding BorderBrush}"> 
           <!-- This is the container to host your Window.Content --> 
           <ContentPresenter/> 
          </Border> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Application.Resources> 
</Application> 

그리고 당신은 그런 "패턴"을 공유하는 단 하나의 속성 Style를 사용할 수 있습니다 :

enter image description here

App.xaml에 아래의 코드를 작성하고 당신은 위의 사진을 얻을 것이다

<Window x:Class="Walterlv.Demo.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Style="{StaticResource Style.Window.Default}"> 

</Window> 

App.xaml 파일에 다른 종류의 스타일을 정의하고의 모든 사용자를 선택할 수 있습니다.필요합니다.

+0

그것은 환상적이고 그것이 내가 뭘 필요한지 감사합니다 Logged –