Resize WPF Frame
-
2012年8月3日 5:53
hey can you plz tell me how to resize a frame, i am using this frame to call another page inside it the code is as follows
<Popup Name="TextModulePopup" VerticalAlignment="Stretch" >
<Frame HorizontalAlignment="Stretch" Width="auto" Height="260" Margin="10,240,10,10" Name="SelectTextModuleFrame" />
</Popup>i am navigating another page (Page2) inside this frame
and on the page2 i am using this code to resize
XAML
<Thumb DragDelta="onDragDelta" />
C#
private void onDragDelta(object sender, DragDeltaEventArgs e)
{
double yadjust = wmp.SelectTextModuleFrame.Height + e.VerticalChange;
if (yadjust > 100)
{
wmp.SelectTextModuleFrame.Height = yadjust;
}
}its workign insanely and resizing is very rough and the frame vibrates when i try to resize it
- 已编辑 Atif Imtiaz 2012年8月3日 5:53
全部回复
-
2012年8月3日 9:52
<Window x:Class="ForumProjects.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="700" Width="800"> <StackPanel> <Button Click="ShowPopup"> <Grid> <TextBlock>Show Popup</TextBlock> <Popup Name="Popup" StaysOpen="False" Width="100" Height="100"> <Grid Background="Blue"> <Thumb HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="16" Height="16" DragStarted="onDragStarted" DragDelta="onDragDelta" DragCompleted="onDragCompleted"/> </Grid> </Popup> </Grid> </Button> </StackPanel> </Window> namespace ForumProjects { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ShowPopup(object sender, RoutedEventArgs e) { this.Popup.IsOpen = true; } private void onDragStarted(object sender, DragStartedEventArgs e) { Thumb t = (Thumb)sender; t.Cursor = Cursors.Hand; } private void onDragDelta(object sender, DragDeltaEventArgs e) { double yadjust = this.Popup.Height + e.VerticalChange; double xadjust = this.Popup.Width + e.HorizontalChange; if ((xadjust >= 0) && (yadjust >= 0)) { this.Popup.Width = xadjust; this.Popup.Height = yadjust; } } private void onDragCompleted(object sender, DragCompletedEventArgs e) { Thumb t = (Thumb)sender; t.Cursor = null; } } }
Popup control has not build in support for grip size. But we can do this by ourself. The following example shows how to use Thumb control to do this.
Try this link also:
http://kentb.blogspot.in/2007/04/resizer-wpf-control.html
Sivalingam
- 已编辑 Sivalingam Ramasamy 2012年8月3日 9:53
-
2012年8月6日 5:58版主
Hi Atif Imtiaz,
There is a sample you could refer to:
MainWindow.xaml:
<Grid Background="Transparent" PreviewMouseDown="Grid_PreviewMouseDown"> <Popup AllowsTransparency="True" Name="TextModulePopup" VerticalAlignment="Stretch" > <Frame Background="Aqua" Source="Page1.xaml" HorizontalAlignment="Stretch" Width="200" Height="260" Name="SelectTextModuleFrame" /> </Popup> </Grid>private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e) { TextModulePopup.IsOpen = true; }Page1.xaml:
<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="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"/> <TextBlock Grid.Row="1" Grid.Column="1" Text="Your Content Here"/> </Grid>public partial class Page1 : Page { public Page1() { InitializeComponent(); } private void Thumb_DragDelta(object sender, DragDeltaEventArgs e) { var str = (string)((Thumb)sender).Tag; Frame frm = GetAncestorByType(this, typeof(Frame)) as Frame; if (str.Contains("T")) { // frm.Height = Math.Min(Math.Max(frm.MinHeight, frm.ActualHeight - e.VerticalChange), frm.MaxHeight); e.Handled = true; } if (str.Contains("L")) { frm.Width = Math.Min(Math.Max(frm.MinWidth, frm.ActualWidth - e.HorizontalChange), frm.MaxWidth); // Canvas.SetLeft(Content, Canvas.GetLeft(Content) - Content.Width + Content.ActualWidth); } if (str.Contains("B")) { frm.Height = Math.Min(Math.Max(frm.MinHeight, frm.ActualHeight + e.VerticalChange), frm.MaxHeight); } if (str.Contains("R")) { frm.Width = Math.Min(Math.Max(frm.MinWidth, frm.ActualWidth + e.HorizontalChange), frm.MaxWidth); } e.Handled = true; } public static DependencyObject GetAncestorByType(DependencyObject element, Type type) { if (element == null) return null; if (element.GetType() == type) return element; return GetAncestorByType(VisualTreeHelper.GetParent(element), type); } }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.
- 已标记为答案 Sheldon _XiaoModerator 2012年8月17日 7:09
-
2012年8月17日 7:09版主
Hi Atif Imtiaz,
I am marking your issue as "Answered", if you have new findings about your issue, please let me know.
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.

