Arrangement of elements on a maximized window

I have a window with WindowState="Maximized"(which is also equal AllowsTransparency="True" Background="Transparent" WindowStyle="None"if that matters), and there is an element in the upper left corner of the window Image.

But the actual window.Left position = -8 and window.Top = -8.

So my image is cropped for these values.

I made such a hack to avoid this:

image1.Margin = new Thickness(-this.Left - 1, -this.Top - 1, 0, 0);

but, as you see, it looks weird. What is the correct way to place an element in the real upper left corner of the screen?

+3
source share
3 answers

I can not reproduce your problem.

Here is what I tried:

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        WindowState="Maximized">

    <Grid>
        <Image Source="E:\testImages\test.bmp" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left" />
    </Grid>

</Window>

and with this, indeed, the window has a position (-8, -8), which is normal, since this is the way MS Windows "hide" the borders of windows ...

, , , , .

Hack, , 8 8xpx .

- ,


, , , , "AllowsTransparency" true.

, ...

+1

,

<Window x:Class="Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    WindowState="Maximized"
    AllowsTransparency="True" 
    WindowStyle="None" name="Window1">

<Grid>


<Grid.Style>
    <Style TargetType="{x:Type Grid}">
        <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=Window1, Path=WindowState}" Value="Maximized">
                <Setter Property="Margin" Value="5"/> // set your own values
            </DataTrigger>
        </Style.Triggers>
    </Style>
    </Grid.Style>




    <Image Source="E:\testImages\test.bmp" Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left" />
</Grid>

+1

ViewBox. :

<ViewBox>
  <Grid>
    <Image ..../>
  </Grid>
</ViewBox>

ViewBox , .

0

All Articles