Moin,
ich bin gerade dabei, mir ein Formular mit eigener Titelleiste zu erstellen. Das klappt auch soweit, jedoch stehe ich jetzt vor dem Problem des Maximierens.
wenn ich das Programm maximiere, wird das Formular größer als mein Bildschirm.
Ich hoffe ihr könnt mir helfen, herauszufinden, warum das Formular zu groß wird und wie ich das Formular richtig maximiere.
Gibt es eigentlich eine einfachere Methode das Formular zu resizen, als alles selbst zu berechnen?
Gruß
HamburgerJungeJr
P.S. Bin relativ neu mit WPF Verbesserungen sind daher erwünscht
Formular-XAML
Spoiler anzeigen
Titelleiste-XAML
Spoiler anzeigen
Titelleiste-VB
Spoiler anzeigen
ich bin gerade dabei, mir ein Formular mit eigener Titelleiste zu erstellen. Das klappt auch soweit, jedoch stehe ich jetzt vor dem Problem des Maximierens.
wenn ich das Programm maximiere, wird das Formular größer als mein Bildschirm.
Ich hoffe ihr könnt mir helfen, herauszufinden, warum das Formular zu groß wird und wie ich das Formular richtig maximiere.
Gibt es eigentlich eine einfachere Methode das Formular zu resizen, als alles selbst zu berechnen?
Gruß
HamburgerJungeJr
P.S. Bin relativ neu mit WPF Verbesserungen sind daher erwünscht
Formular-XAML
XML-Quellcode
- <Window
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="clr-namespace:WPF-Test" x:Class="MainWindow"
- Title="MainWindow" Height="350" Width="525" WindowStyle="none" AllowsTransparency="True"
- Background="Transparent" Icon="Resources/favicon.ico" >
- <Window.Resources>
- <SolidColorBrush x:Key="formBorderColor" Color="#FFA200" />
- <Style x:Key="formBorderStyle" TargetType="Border">
- <Setter Property="BorderThickness" Value="3" />
- <Setter Property="BorderBrush" Value="{StaticResource formBorderColor}" />
- </Style>
- </Window.Resources>
- <Grid Background="white">
- <DockPanel LastChildFill="true" x:Name="dpMain">
- <DockPanel LastChildFill="true" Height="30px" x:Name="dpTitlebar" DockPanel.Dock="Top">
- <local:TitleBar VerticalAlignment="Stretch"/>
- </DockPanel>
- <Grid DockPanel.Dock="Bottom">
- <Border Style="{StaticResource formBorderStyle}">
- </Border>
- </Grid>
- </DockPanel>
- </Grid>
- </Window>
Titelleiste-XAML
XML-Quellcode
- <UserControl x:Class="TitleBar"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- mc:Ignorable="d"
- d:DesignHeight="30" d:DesignWidth="500" Background="#FFFFA200" MouseLeftButtonDown="UserControl_MouseLeftButtonDown">
- <UserControl.Resources>
- <SolidColorBrush x:Key="buttonBackground" Color="#FFA200" />
- <SolidColorBrush x:Key="buttonBorder" Color="#FFA200" />
- <SolidColorBrush x:Key="buttonBackgroundMouseOver" Color="#FFC080" />
- <SolidColorBrush x:Key="buttonBorderMouseOver" Color="#FFC080" />
- <SolidColorBrush x:Key="buttonBackgroundPressed" Color="#FF8000" />
- <SolidColorBrush x:Key="buttonBorderPressed" Color="#FF8000" />
- <SolidColorBrush x:Key="buttonForeColor" Color="#000000" />
- <SolidColorBrush x:Key="titleForeColor" Color="#FFFFFF" />
- <Style x:Key="titleStyle" TargetType="TextBlock">
- <Setter Property="FontSize" Value="16" />
- <Setter Property="FontFamily" Value="Segoe UI" />
- <Setter Property="Foreground" Value="{StaticResource titleForeColor}" />
- <Setter Property="HorizontalAlignment" Value="Left" />
- <Setter Property="VerticalAlignment" Value="Center" />
- <Setter Property="Margin" Value="10,0,0,0" />
- </Style>
- <Style x:Key="iconStyle" TargetType="Image">
- <Setter Property="Margin" Value="3,3,0,3" />
- </Style>
- <Style x:Key="buttonStyle" TargetType="Button">
- <Setter Property="Margin" Value="3,0,0,3" />
- <Setter Property="Padding" Value="0,0,0,5" />
- <Setter Property="Width" Value="30" />
- <Setter Property="HorizontalAlignment" Value="Right" />
- <Setter Property="VerticalAlignment" Value="Stretch" />
- <Setter Property="BorderThickness" Value="1" />
- <Setter Property="Background" Value="{StaticResource buttonBackground}" />
- <Setter Property="BorderBrush" Value="{StaticResource buttonBorder}" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Button}">
- <Border Background="{TemplateBinding Background}">
- <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
- </Border>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- <Style.Triggers>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter Property="Background" Value="{StaticResource buttonBackgroundMouseOver}" />
- <Setter Property="BorderBrush" Value="{StaticResource buttonBorderMouseOver}" />
- </Trigger>
- <Trigger Property="Button.IsPressed" Value="True">
- <Setter Property="Background" Value="{StaticResource buttonBackgroundPressed}" />
- <Setter Property="BorderBrush" Value="{StaticResource buttonBorderPressed}" />
- </Trigger>
- </Style.Triggers>
- </Style>
- <Style x:Key="buttonPathStyle" TargetType="Path">
- <Setter Property="Fill" Value="{StaticResource buttonForeColor}" />
- <Setter Property="Stretch" Value="Uniform" />
- <Setter Property="Width" Value="10" />
- <Setter Property="Margin" Value="0,0,0,10" />
- </Style>
- </UserControl.Resources>
- <Grid>
- <DockPanel LastChildFill="True">
- <Image DockPanel.Dock="Left" Source="{Binding Icon,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}" Style="{StaticResource iconStyle}"/>
- <Button x:Name="sClose" DockPanel.Dock="Right" Height="30" Margin="5,0,0,0" Style="{StaticResource buttonStyle}">
- <Path Data="F1M54.0573,47.8776L38.1771,31.9974 54.0547,16.1198C55.7604,14.4141 55.7604,11.6511 54.0573,9.94531 52.3516,8.23962 49.5859,8.23962 47.8802,9.94531L32.0026,25.8229 16.1224,9.94531C14.4167,8.23962 11.6511,8.23962 9.94794,9.94531 8.24219,11.6511 8.24219,14.4141 9.94794,16.1198L25.8255,32 9.94794,47.8776C8.24219,49.5834 8.24219,52.3477 9.94794,54.0534 11.6511,55.7572 14.4167,55.7585 16.1224,54.0534L32.0026,38.1745 47.8802,54.0534C49.5859,55.7585 52.3516,55.7572 54.0573,54.0534 55.7604,52.3477 55.763,49.5834 54.0573,47.8776z" Style="{StaticResource buttonPathStyle}" />
- </Button>
- <Button x:Name="sMaximize" DockPanel.Dock="Right" Height="30" Margin="5,0,0,0" Style="{StaticResource buttonStyle}">
- <Path Data="M4.3685131,23.127279L4.3685131,47.283243 47.117023,47.283243 47.117023,23.127279z M0,10.684L53.755001,10.684 53.755001,51.668001 0,51.668001z M8.5679998,0L58.668022,0 64,0 64,5.6864691 64,45.317999 58.668022,45.317999 58.668022,5.6864691 8.5679998,5.6864691z" Style="{StaticResource buttonPathStyle}" />
- </Button>
- <Button x:Name="sMinimize" DockPanel.Dock="Right" Height="30" Margin="5,0,0,0" Style="{StaticResource buttonStyle}">
- <Path Data="M0,20L53.333,20 53.333,8.888 0,8.888z" Style="{StaticResource buttonPathStyle}" />
- </Button>
- <TextBlock x:Name="tbTitle" Text="{Binding Title,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}" DockPanel.Dock="Left" Style="{StaticResource titleStyle}"/>
- </DockPanel>
- </Grid>
- </UserControl>
Titelleiste-VB
VB.NET-Quellcode
- Imports System.Windows.Window
- Public Class TitleBar
- Private Sub UserControl_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
- GetWindow(Me).DragMove()
- End Sub
- Private Sub sClose_Click(sender As Object, e As RoutedEventArgs) Handles sClose.Click
- GetWindow(Me).Close()
- End Sub
- Private Sub sMaximize_Click(sender As Object, e As RoutedEventArgs) Handles sMaximize.Click
- With GetWindow(Me)
- If .WindowState = Windows.WindowState.Normal Then
- .WindowState = WindowState.Maximized
- Else
- .WindowState = Windows.WindowState.Normal
- End If
- End With
- End Sub
- End Class
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „HamburgerJungeJr“ ()