2011-09-12 11 views
3

以下のXAMLは変わる唯一の事は、それがホストすることをユーザーコントロールである私は、いくつかのプレゼンテーションで使用していますウィンドウのためです: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> 

痛みは

  1. を指して、私はInputBindingsを作る方法を見ないWindowStartupLocation
  2. のためのプロパティのセッターを見つけることができませんでしたスタイルの一部

私は使用する必要があるスタイルやアプローチを使用していますか?上記のプロパティはどのように設定できますか?

乾杯。
Berryl

答えて

4

は、なぜあなたは、単にコンテンツなしでこのタイプのウィンドウを作成し、それを表示する前にそのContentとしてお好みのUserControlを追加しませんか?あなたは複数のサブクラスWindowを必要とせず、スタイルを混乱させる必要もありません。私たちは「(いくつかの適切なUserControlを使用しdは再文字列は通常、あなたが)に、ウィンドウの内容を設定する」

簡単な例、:

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

あなたは複雑なUserControlを挿入したい場合は、この1つは言います:

<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

私はトンを提案しますスタイルに設定されている振る舞いの問題を解決します。

ちょうどGoogleが付けた動作wpf

関連する問題