tags:

views:

83

answers:

1

Hi i have a window where i add a new usercontrol to with an image, i simply want to center the image (thus the control) in the middle of the screen (both vertically and horzontally) can only get the vertical on e to work. Im gonna swap content in the dockpanel from my codebehind and want to show this startupd screen before i start doing my slideshow ui, this means that the content is set from the condebehind:

my window:

<Window x:Class="GreenWebPlayerWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="512" Width="853" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen">
    <DockPanel Width="Auto" Height="Auto" Name="TransitionContainer" Background="Black" Margin="0" LastChildFill="True"></DockPanel>
    </Window>

my usercontrol

<UserControl x:Class="GreenWebPlayerWPF.FrontPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
        <DockPanel Background="Black">
            <Image Name="image1" Stretch="None" Source="/GreenWebPlayerWPF;component/gw.png" />
                </DockPanel>
    </UserControl>

Please not that im ng maximized/full screen, Anyone?

+1  A: 

Use a Grid:

  <Grid>  
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="Auto"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="*"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <!-- Replace with your UserControl -->
    <Button Content="Foo" Grid.Column="1" Grid.Row="1"/>
  </Grid>

You can dock it inside your DockPanel (if you must have a DockPanel there) to stretch. And, of course, while the above is all markup, you can just as easily create such a grid from code.

Pavel Minaev
Thx a bunch, it works :-)
H4mm3rHead