2011-09-12 8 views
3

아래의 XAML은 다양 유일한 것은 그것이 호스팅하는 UserControl을하다 내가 여러 프리젠 테이션에서 사용하고 창입니다 :WPF 창을 다시 사용하려고

<Window x:Class="Smack.ConstructionAdmin.Presentation.Wpf.Views.Admin.Employees.EmployeeShellView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:local="clr-namespace:Smack.ConstructionAdmin.Presentation.Wpf.Views.Admin.Employees" 
     xmlns:s="clr-namespace:Smack.ConstructionAdmin.Presentation.Wpf" 
     xmlns:cmdRef="clr-namespace:Smack.Core.Presentation.Wpf.ViewModels.Commands.Reference;assembly=Smack.Core.Presentation.Wpf" 

     Background="{DynamicResource WaveWindowBackground}" 
     Title="{Binding Source={x:Static s:Strings.AppName}}" 
     Icon="pack://application:,,,/Smack.ConstructionAdmin.Presentation.Wpf;component/Images/Time-Machine_16.png" 
     FontFamily="Arial" 
     WindowStartupLocation="CenterScreen" Width="750" Height="600" 
     > 
    <DockPanel> 
     <local:EmployeeShellUserControl DataContext="{Binding}" /> 
    </DockPanel> 

    <Window.InputBindings> 
     <cmdRef:KeyBindingEx CommandReference="{Binding AddCommand}"/> 
     <cmdRef:KeyBindingEx CommandReference="{Binding EditCommand}"/> 
     <cmdRef:KeyBindingEx CommandReference="{Binding DeleteCommand}"/> 
    </Window.InputBindings> 

</Window> 

그래서 그것을 재사용 의미를 보인다는 어떻게 든 변하지 않는 부분. 여기에 스타일을 그렇게 나의 첫 번째 시도이다

<Style x:Key="MyWindowStyle" TargetType="{x:Type Window}"> 
    <Setter Property="Background" Value="{DynamicResource WaveWindowBackground}"></Setter> 
    <Setter Property="FontFamily" Value="Arial"></Setter> 
    <Setter Property="Height" Value="600"></Setter> 
    <Setter Property="Width" Value="750"></Setter> 
    <Setter Property="Title" Value="{Binding AppName}"></Setter> 
    <Setter Property="Icon" Value="{Binding IconUri}"></Setter> 
</Style> 

고통 포인트

내가 WindowStartupLocation에 대한 속성 setter를 찾을 수 없습니다
    1. 내가있는 InputBindings을 만드는 방법을 볼 수 없습니다
    2. 스타일의 부분

    스타일을 올바르게 사용하거나 거기에 사용할 다른 기술이 있습니까? 위의 속성을 어떻게 설정할 수 있습니까?

    건배.
    Berryl

  • 답변

    4

    왜 당신은 단순히 내용없이이 유형의 창을 생성하지 않는 한 다음 그것을 보여주는 전에 Content으로 당신의 선택의 UserControl을 추가? Window 하위 클래스가 여러 개 필요하지 않으므로 스타일을 혼란스럽게 만들 필요가 없습니다.

    var window = new EmployeeShellView(); 
    window.Content = "Hello world!"; // set to your UserControl 
    window.Show(); 
    

    당신이 복잡한 UserControl을 삽입하려면

    이 한 말 : 우리가 '(사용하는 몇 가지 적절한 UserControl을 거라고 문자열 일반적으로 당신이)에 윈도우의 내용을 설정 다시'

    예제이다 :

    <UserControl x:Class="MyControl"> 
        <DockPanel> 
         <local:EmployeeShellUserControl DataContext="{Binding}" /> 
        </DockPanel> 
    </UserControl> 
    

    당신은 할 것 :

    var window = new EmployeeShellView(); 
    window.Content = new MyControl(); 
    window.Show(); 
    
    +0

    완벽하게 들립니다. 그러나 당신이 의미하는 것이 확실하지 않습니다 - 더 잘 설명하기 위해 일부 코드 및/또는 xaml을 긁을 수 있습니까? – Berryl

    +0

    @Berryl : 예제를 추가했습니다. 괜찮습니까? – Jon

    +0

    그래서 ShellView를있는 그대로두고 인스턴스를 만들고 내용을 설정 하시겠습니까? 기존 UserControl을 대체하는 부분은 Content가되거나 Content 속성의 정의는 어떻게됩니까? – Berryl

    0

    나는 t을 제안 스타일에 설정 될 첨부 된 동작에 대한 문제를 극복하십시오.

    그냥 Google이 첨부 한 동작 wpf

    관련 문제