积极答复者
WPF 非规则窗体 如何拉伸 改变大小呢 ? 不知道失哪个方法或者是哪个属性

问题
答案
-
我一般这么做:
<Canvas> <Border x:Name="Content" Canvas.Left="500" Canvas.Top="500" Width="500" Height="500" MinWidth="100" MinHeight="100" CornerRadius="2" Background="#FF3A3A3A"> <Border.Effect> <DropShadowEffect ShadowDepth="0" BlurRadius="10"/> </Border.Effect> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="8" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="8" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="8" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="8" /> </Grid.RowDefinitions> <Thumb Opacity="0" Grid.Row="0" Grid.Column="0" Cursor="SizeNWSE" Tag="TL" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="0" Grid.Column="2" Cursor="SizeNESW" Tag="TR" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="0" Cursor="SizeNESW" Tag="BL" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="2" Cursor="SizeNWSE" Tag="BR" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="0" Grid.Column="1" Cursor="SizeNS" Tag="T" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="1" Cursor="SizeNS" Tag="B" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Cursor="SizeWE" Tag="L" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Cursor="SizeWE" Tag="R" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="1" Cursor="SizeAll" Tag="M" DragDelta="Thumb_DragDelta"/> </Grid> </Border> </Canvas>
private void Thumb_DragDelta(object sender, DragDeltaEventArgs e) { var str = (string)((Thumb)sender).Tag; if (str.Contains("T")) { Content.Height = Math.Min(Math.Max(Content.MinHeight, Content.ActualHeight - e.VerticalChange), Content.MaxHeight); Canvas.SetTop(Content, Canvas.GetTop(Content) - Content.Height + Content.ActualHeight); } if (str.Contains("L")) { Content.Width = Math.Min(Math.Max(Content.MinWidth, Content.ActualWidth - e.HorizontalChange), Content.MaxWidth); Canvas.SetLeft(Content, Canvas.GetLeft(Content) - Content.Width + Content.ActualWidth); } if (str.Contains("B")) { Content.Height = Math.Min(Math.Max(Content.MinHeight, Content.ActualHeight + e.VerticalChange), Content.MaxHeight); } if (str.Contains("R")) { Content.Width = Math.Min(Math.Max(Content.MinWidth, Content.ActualWidth + e.HorizontalChange), Content.MaxWidth); } if (str.Contains("M")) { Canvas.SetTop(Content, Canvas.GetTop(Content) + e.VerticalChange); Canvas.SetLeft(Content, Canvas.GetLeft(Content) + e.HorizontalChange); } e.Handled = true; }
Window : WindowStyle="None" Background="Transparent" AllowsTransparency="True"
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2012年3月5日 16:40
- 已标记为答案 没力敲键盘 2012年3月9日 11:37
-
- 已建议为答案 Sheldon _XiaoModerator 2012年3月6日 2:54
- 已标记为答案 Jie BaoModerator 2012年4月19日 3:44
全部回复
-
我一般这么做:
<Canvas> <Border x:Name="Content" Canvas.Left="500" Canvas.Top="500" Width="500" Height="500" MinWidth="100" MinHeight="100" CornerRadius="2" Background="#FF3A3A3A"> <Border.Effect> <DropShadowEffect ShadowDepth="0" BlurRadius="10"/> </Border.Effect> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="8" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="8" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="8" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="8" /> </Grid.RowDefinitions> <Thumb Opacity="0" Grid.Row="0" Grid.Column="0" Cursor="SizeNWSE" Tag="TL" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="0" Grid.Column="2" Cursor="SizeNESW" Tag="TR" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="0" Cursor="SizeNESW" Tag="BL" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="2" Cursor="SizeNWSE" Tag="BR" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="0" Grid.Column="1" Cursor="SizeNS" Tag="T" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="3" Grid.Column="1" Cursor="SizeNS" Tag="B" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Cursor="SizeWE" Tag="L" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Cursor="SizeWE" Tag="R" DragDelta="Thumb_DragDelta"/> <Thumb Opacity="0" Grid.Row="1" Grid.Column="1" Cursor="SizeAll" Tag="M" DragDelta="Thumb_DragDelta"/> </Grid> </Border> </Canvas>
private void Thumb_DragDelta(object sender, DragDeltaEventArgs e) { var str = (string)((Thumb)sender).Tag; if (str.Contains("T")) { Content.Height = Math.Min(Math.Max(Content.MinHeight, Content.ActualHeight - e.VerticalChange), Content.MaxHeight); Canvas.SetTop(Content, Canvas.GetTop(Content) - Content.Height + Content.ActualHeight); } if (str.Contains("L")) { Content.Width = Math.Min(Math.Max(Content.MinWidth, Content.ActualWidth - e.HorizontalChange), Content.MaxWidth); Canvas.SetLeft(Content, Canvas.GetLeft(Content) - Content.Width + Content.ActualWidth); } if (str.Contains("B")) { Content.Height = Math.Min(Math.Max(Content.MinHeight, Content.ActualHeight + e.VerticalChange), Content.MaxHeight); } if (str.Contains("R")) { Content.Width = Math.Min(Math.Max(Content.MinWidth, Content.ActualWidth + e.HorizontalChange), Content.MaxWidth); } if (str.Contains("M")) { Canvas.SetTop(Content, Canvas.GetTop(Content) + e.VerticalChange); Canvas.SetLeft(Content, Canvas.GetLeft(Content) + e.HorizontalChange); } e.Handled = true; }
Window : WindowStyle="None" Background="Transparent" AllowsTransparency="True"
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2012年3月5日 16:40
- 已标记为答案 没力敲键盘 2012年3月9日 11:37
-
- 已建议为答案 Sheldon _XiaoModerator 2012年3月6日 2:54
- 已标记为答案 Jie BaoModerator 2012年4月19日 3:44
-
有个小问题 向上resize的时候窗口下边缘浮动,是我本地的问题 还是其他的
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.