views:

255

answers:

2

I'm using the WPF Shell Integration Library to create a custom chrome of my wpf app. All is good, but when maximizing the app, 6 or 7 pixels are out of the screen.

alt text

This is the code I'm using:

<Style TargetType="{x:Type local:MainWindow}">
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome
                    ResizeBorderThickness="6"
                    CaptionHeight="10"
                    CornerRadius="0"
                    GlassFrameThickness="1"/>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MainWindow}">
                    <Grid>
                        <Border BorderThickness="1" BorderBrush="#389FD1" Background="#389FD1">
                            <ContentPresenter Margin="0,22,0,0" Content="{TemplateBinding Content}"/>
                        </Border>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" >
                            <TextBlock Text="{Binding NombreUsuario}" Foreground="White" Margin="5,5,20,5" Opacity=".8" />
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMinimize" shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                <Image Height="10" Width="10" Source="/Resources/Images/minimize.png" />
                            </Button>
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMaximizeRestore" shell:WindowChrome.IsHitTestVisibleInChrome="True" >
                                <Image Height="10" Width="10" Source="/Resources/Images/maximize.png" />
                            </Button>
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowClose" shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                <Image Height="10" Width="10" Source="/Resources/Images/close.png" />
                            </Button>
                        </StackPanel>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
+4  A: 

Windows crops the edges of the window when it's maximized to obscure what would normally be the resize edges. You can get around this by putting a proxy border between the window and your content and then inflate the thickness when it's maximized.

I modified the example that came with the lib to do this, the same basic change could be made to your sample:

<ControlTemplate TargetType="{x:Type local:SelectableChromeWindow}">
  <Border BorderBrush="Green">
    <Border.Style>
      <Style TargetType="{x:Type Border}">
        <Setter Property="BorderThickness" Value="0"/>
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=ThisWindow, Path=WindowState}" Value="Maximized">
            <Setter Property="BorderThickness" Value="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowResizeBorderThickness}"/>
          </DataTrigger>
        </Style.Triggers>
      </Style>
    </Border.Style>
    <Grid [...]/>
  </Border>
</ControlTemplate>

I hope that helps,

Joe Castro
OMG, so beautiful solution. Why didn't I check StackOverflow before start typing my ugly code?
Eduardo Molteni
I have changed to `<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=WindowState}" Value="Maximized">` to make it work, not sure why
Eduardo Molteni
That's better than what I did. I just happened to have the Window named so I could refer to it that way in my case.
Joe Castro
A: 

Did you lift code from MetroTwit? The XAML oddly matches... Not a big issue, but pretty silly. (http://www.metrotwit.com/)

Rafael Rivera
How could I? The code is not public AFAIK. The first part it's from the WPF Shell library sample, the second is just made myself. Do you mean the MetroTwit code use `{StaticResource ImageButton}`? That will be a BIG coincidence, the rest if boring common stuff.
Eduardo Molteni
Now I'm curious about the coincidence. Could you post the snippet from MetroTwit?
Eduardo Molteni
The window screenshot you provided matches identically with MetroTwit when compared side-by-side. Perhaps you were just "inspired"?
Rafael Rivera
Yes, the look is something like Metrotwit (inspired by it and others like Zune and "Contoso App" from MS). It's funny that you say it's identical, because I **hate** my buttons (made by hand in a sloppy way), Metrotwit look much better and sharp. Anyway, I thought that you were referring to the XAML posted, not the screenshot.
Eduardo Molteni