2

I had asked this question the other day. Now, I'm trying to apply the same practice to make all my windows, and have CenterScreen as it's default WindowStartupLocation. I've tried typing:

<Style TargetType="Window">
    <Setter Property="WindowStartupLocation">

    </Setter>
</Style>

However, apparently WindowStartupLocation isn't a supported property for this. Is there a way to accomplish this that I'm missing, or am I going to have to manually change this for all windows?

Community
  • 1
  • 1
PiousVenom
  • 6,888
  • 11
  • 47
  • 86

1 Answers1

-1

App.xaml

<Application.Resources>
    <ResourceDictionary>
        <Style x:Key="WindowStyle" TargetType="Window">
            <Setter Property="SizeToContent" Value="WidthAndHeight" />
            <Setter Property="ResizeMode" Value="CanMinimize" />
        </Style>
        <WindowStartupLocation x:Key="WSL">CenterOwner</WindowStartupLocation>
    </ResourceDictionary>
</Application.Resources>

Window

<Window x:Class="WpfApplication7.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow"        Width="525"        Height="350"        WindowStartupLocation="{StaticResource WSL}"        Style="{StaticResource WindowStyle}">
    <Window.Resources />
    <Grid />
</Window>
Rudi
  • 926
  • 2
  • 19
  • 38
  • While this does do what I want, to an extent, what I'm really looking for is for when I create a new `window`, the `WindowStartupLocation` is by default already at `CenterScreen`. – PiousVenom May 28 '13 at 15:11
  • This answer was copied and poorly pasted from http://stackoverflow.com/questions/10596515/setting-windowstartuplocation-from-resourcedictionary-throws-xamlparseexception . – Adam Plocher Mar 05 '16 at 07:21