大佬教程收集整理的这篇文章主要介绍了WPF / XAML:如何调整没有边框的窗口大小?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
alt text http://cartesia.pbworks.com/f/1265489984/Resize.png
我似乎无法让Window标签正常显示…(只需拿出撇号就可以了.)任何人有什么想法?
XAML
<'Window x:Class="Article_1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="Article_1_Resizing" Background="Transparent" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" MinHeight="100" Height="400" MaxHeight="600" MinWidth="100" Width="400" MaxWidth="800"> <Window.Resources> <SolidColorBrush x:Key="Brush_ChromeBackground" Color="#FFC8D1E0"/> <SolidColorBrush x:Key="Brush_ChromeBorder" Color="#FFA0A0A0"/> <sys:Double x:Key="Chrome_BorderWidth">5</sys:Double> </Window.Resources> <Border x:Name="Border_Chrome" BorderBrush="{StaticResource Brush_ChromeBorder}" BorderThickness="1,1,1" CornerRadius="2,2,2" Width="Auto"> <Grid x:Name="Grid" ShowGridLines="False"> <Grid.RowDeFinitions> <RowDeFinition x:Name="row_Top" Height="Auto"/> <RowDeFinition x:Name="row_Middle" Height="*"/> <RowDeFinition x:Name="row_Bottom" Height="Auto"/> </Grid.RowDeFinitions> <Grid.ColumnDeFinitions> <ColumnDeFinition x:Name="col_Left" Width="Auto"/> <ColumnDeFinition x:Name="col_Middle" Width="*"/> <ColumnDeFinition x:Name="col_Right" Width="Auto"/> </Grid.ColumnDeFinitions> <!-- Top Row --> <Rectangle x:Name="Rectangle_TopLeft" Grid.Row="0" Grid.Column="0" Width="{StaticResource Chrome_BorderWidth}" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNWSE" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <Rectangle x:Name="Rectangle_TopMiddle" Grid.Row="0" Grid.Column="1" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNS" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <Rectangle x:Name="Rectangle_TopRight" Grid.Row="0" Grid.Column="2" Width="{StaticResource Chrome_BorderWidth}" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNESW" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <!-- Middle Row --> <Rectangle x:Name="Rectangle_MiddleLeft" Grid.Row="1" Grid.Column="0" Width="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeWE" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <!-- Content --> <Label Content="Mouse Down to Move - Double Click to Close" Grid.Row="1" Grid.Column="1" Background="White" Foreground="Black" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalAlignment="Stretch" VerticalContentAlignment="Center" MouseDoubleClick="_Close" MouseLeftButtonDown="Move"/> <Rectangle x:Name="Rectangle_MiddleRight" Grid.Row="1" Grid.Column="2" Width="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeWE" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <!-- Bottom Row --> <Rectangle x:Name="Rectangle_BottomLeft" Grid.Row="2" Grid.Column="0" Width="{StaticResource Chrome_BorderWidth}" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNESW" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <Rectangle x:Name="Rectangle_BottomMiddle" Grid.Row="2" Grid.Column="1" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNS" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> <Rectangle x:Name="Rectangle_BottomRight" Grid.Row="2" Grid.Column="2" Width="{StaticResource Chrome_BorderWidth}" Height="{StaticResource Chrome_BorderWidth}" Fill="{StaticResource Brush_ChromeBackground}" Cursor="SizeNWSE" MouseLeftButtonDown="Resize_Begin" MouseLeftButtonUp="Resize_End" MouseMove="Resize"/> </Grid> </Border> </Window>
代码背后
Partial Public Class Article_1 Public Sub New() InitializeComponent() Initialize_Sizes End Sub Private isResizing as Boolean = False Private Const CURSOR_OFFSET_SMALL As Double = 3 Private Const CURSOR_OFFSET_LARGE As Double = 5 Private _x As Double = 0 Private _Y As Double = 0 Private Sub Initialize_Sizes Dim _MinWidth As Double = Rectangle_MiddleLeft.Width + _ Rectangle_BottomRight.Width + _ border_Chrome.BorderThickness.Left + _ border_Chrome.BorderThickness.Right + 1 If MinWidth < _MinWidth then _ MinWidth = _MinWidth Dim _MinHeight As Double = Rectangle_TopMiddle.Height + _ Rectangle_BottomMiddle.Height + _ border_Chrome.BorderThickness.top + _ border_Chrome.BorderThickness.Bottom + 1 If MinHeight < _MinHeight then _ MinHeight = _MinHeight End Sub Private sub Resize_Begin(sender as object,_ e As MouseEventArgs) isResizing = True DirectCast(sender,Rectangle).CaptureMouse End Sub Private sub Resize_End(sender as object,_ e As MouseEventArgs) isResizing = False DirectCast(sender,Rectangle).ReleaseMouseCapture End Sub Private Sub Resize(sender As Object,_ e As MouseEventArgs) If isResizing = False then Exit Sub _x = e.GetPosition(me).x _y = e.GetPosition(me).Y Select Case DirectCast(sender,Rectangle).Name Case "Rectangle_TopLeft" : Resize_Width_Left Resize_Height_Top Case "Rectangle_TopMiddle" : Resize_Height_Top Case "Rectangle_TopRight" : Resize_Width_Right Resize_Height_Top Case "Rectangle_MiddleLeft" : Resize_Width_Left Case "Rectangle_MiddleRight" : Resize_Width_Right Case "Rectangle_BottomLeft" : Resize_Width_Left Resize_Height_Bottom Case "Rectangle_BottomMiddle" : Resize_Height_Bottom Case "Rectangle_BottomRight" : Resize_Width_Right Resize_Height_Bottom Case else : MessageBox.Show("Error in Resize") End Select End Sub Private Sub Resize_Width_Left _x -= CURSOR_OFFSET_SMALL If Width - _x >= MinWidth Then If Width - _x <= MaxWidth then Width -= _x Left += _x End If End If End Sub Private Sub Resize_Width_Right _x += CURSOR_OFFSET_LARGE Select Case _x Case Is < MinWidth : width = MinWidth Case Is > MaxWidth : Width = MaxWidth Case Else : Width = _x End Select End Sub Private Sub Resize_Height_Top _y -= CURSOR_OFFSET_SMALL If Height - _y >= MinHeight Then If Height - _y <= MaxHeight then Height -= _y Top += _y End If End If End Sub Private Sub Resize_Height_Bottom _y += CURSOR_OFFSET_SMALL Select Case _y Case Is < MinHeight : Height = MinHeight Case Is > MaxHeight : Height = MaxHeight Case Else : Height = _y End Select End Sub Private Sub Move(ByVal sender As Object,_ ByVal e As System.Windows.Input.MouseButtonEventArgs) Dim curs As Cursor = Cursor Cursor = Cursors.SizeAll DragMove() Cursor = Curs End Sub Private Sub _Close() Close End Sub End Class
以上是大佬教程为你收集整理的WPF / XAML:如何调整没有边框的窗口大小?全部内容,希望文章能够帮你解决WPF / XAML:如何调整没有边框的窗口大小?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。