I have a Panel that is in a pane group that is in a split container (just like the serverexplorer pane in the example). This pane will be pinned/floated/docked etc. The content of this pane will grow/shrink dynamically as the user makes changes within.
I want to resize the pane, and therefore automatically adjust it’s various containers/states as my contents change. I’m managing to manage some of this but it causes funky interference and mislayouts, obviously I’m going about this the wrong way.
What are my options? Thanks in advance.
14 Answers, 1 is accepted
private void ResizeHorizontal(RadPaneGroup group, double newWidth) |
{ |
var sc = group.Parent as RadSplitContainer; |
if (sc.Parent is RadDocking && |
(RadDockPanel.GetDock(sc) == Dock.Left || RadDockPanel.GetDock(sc) == Dock.Right)) |
{ |
sc.Width = newWidth; |
} |
else |
{ |
// This case needs more efforts. |
if (sc.Orientation == Orientation.Horizontal) |
{ |
double relWidthSum = |
sc.Items.Select(i => |
{ |
var ii = i as DependencyObject; |
if (ii != null) |
{ |
return ProportionalStackPanel.GetRelativeSize(ii).Width; |
} |
return 0; |
}).Sum(); |
double renderWidth = sc.RenderSize.Width; |
Size oldRS = ProportionalStackPanel.GetRelativeSize(group); |
ProportionalStackPanel.SetRelativeSize(group, new Size(relWidthSum * newWidth / renderWidth, oldRS.Height)); |
} |
else |
{ |
// Go up and find the SplitContainer you need to resize. |
} |
} |
} |
private void ResizeVertical(RadPaneGroup group, double newHeight) |
{ |
var sc = group.Parent as RadSplitContainer; |
if (sc.Parent is RadDocking && |
(RadDockPanel.GetDock(sc) == Dock.Top || RadDockPanel.GetDock(sc) == Dock.Bottom)) |
{ |
sc.Height = newHeight; |
} |
else |
{ |
// This case needs more efforts. |
if (sc.Orientation == Orientation.Vertical) |
{ |
double relHeightSum = |
sc.Items.Select(i => |
{ |
var ii = i as DependencyObject; |
if (ii != null) |
{ |
return ProportionalStackPanel.GetRelativeSize(ii).Height; |
} |
return 0; |
}).Sum(); |
double renderHeight = sc.RenderSize.Height; |
Size oldRS = ProportionalStackPanel.GetRelativeSize(group); |
ProportionalStackPanel.SetRelativeSize(group, new Size(oldRS.Width, relHeightSum * newHeight / renderHeight)); |
} |
} |
} |
Regards,
Miroslav Nedyalkov
the Telerik team
Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
could you show an implementation of how these methods work?
I have a simiar issue where i have a radpane and have a stack panel witha number of controls within it, what i want to happen is simple when i float my radpane all of the controls within the stackpanel which is housed in the radpane should resize and scale to fit and show correctly in the radpane no matter if i resize (shrink, enlarge, stretch) my radpane, regarldess if it is floating, docked or tabbed this behaviour should persist: dynamic resizing and rescaling of all controls within the radpane (housed within stackpanel in the radpane)
if you could please post a code sample and xaml on how to do this it would be most appreciated.
Kingsley Magnus-Eweka
<telerikDocking:RadPane Header="Some pane"> |
<Grid> |
<Grid.RowDefinitions> |
<RowDefinition Height="*" /> |
<RowDefinition Height="*" /> |
<RowDefinition Height="*" /> |
<RowDefinition Height="*" /> |
</Grid.RowDefinitions> |
<Button Content="Child 1" Grid.Row="0" /> |
<Button Content="Child 2" Grid.Row="1" /> |
<Button Content="Child 3" Grid.Row="2" /> |
<Button Content="Child 4" Grid.Row="3" /> |
</Grid> |
</telerikDocking:RadPane> |
Regards,
Miroslav Nedyalkov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I will give it a go i currently have a way...i am doing it by adding the Radsplit container in a grid cell.. as illustrated in your demo for the weatherview raddocking in the examples.
I have similar issue.
I have a grid in my pane and when undocked\floating, I want the pane to get resized automatically.
I donot have a pre-defined size whereas I can specify the max height and width and then I want the pane to take exact size needed rather than some blank areas on the grid in edges.
This is my xaml
<telerikDock:RadDocking x:Name="rad_Docking" Height="285" Background="Gainsboro" >
<telerikDock:RadDocking.DocumentHost >
<telerikDock:RadSplitContainer telerikDock:RadDocking.FloatingLocation="10,10" telerikDock:RadDocking.FloatingSize="700,500" >
<telerikDock:RadPaneGroup x:Name="tabMain" AllowDragReorder="False" >
<telerikDock:RadPane Header="Tasks" CanUserClose="False">
<ScrollViewer telerik:StyleManager.Theme="Office_Black" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Button x:Name="tabTask"/>
</ScrollViewer>
</telerikDock:RadPane>
<telerikDock:RadPane Header="History" CanUserClose="False">
<ScrollViewer telerik:StyleManager.Theme="Office_Black" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Button x:Name="tabHist"/>
</ScrollViewer>
</telerikDock:RadPane>
</telerikDock:RadPaneGroup>
</telerikDock:RadSplitContainer>
</telerikDock:RadDocking.DocumentHost>
</telerikDock:RadDocking>
my code-behind event handler:
void rad_Docking_PaneStateChange(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
RadPane pane = e.Source as RadPane;
if (pane != null && pane.IsFloating)
{
ToolWindow toolWindow = pane.ParentOfType<ToolWindow>();
pane.MaxHeight = 700;
pane.MaxWidth = 600;
pane.Height = pane.ActualHeight;
pane.Width = pane.ActualWidth;
pane.UpdateLayout();
}
}
2 Issues:
1. Auto-Height Re-size ; I can provide max and min heights, widths respectively for floating pane
2. Because of the extra space in Floating window and I have placed the usercontrol in Button, I can click the empty area as shown in pic \ Or Can I use any other control with content property inside the rad-pane and scrollviewer?
Bottomline: I need to get the heights fixed properly
Unfortunately, the RadDocking control doesn't support dynamically resizing of RadPanes.
I would suggest you to use telerik:RadDocking.FloatingSize property. For more information, please refer to our online documentation - http://www.telerik.com/help/silverlight/raddocking-features-panes-docked-floating-panes.html
George
the Telerik team
Here is the xaml:
<
UserControl
x:Class
=
"DockingTest.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadDocking
Background
=
"White"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
BorderThickness
=
"0"
>
<
telerik:RadDocumentPane
Visibility
=
"Collapsed"
CanUserClose
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
telerik:RadTileView
ItemsSource
=
"{Binding Items}"
>
<
telerik:RadTileView.ItemTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
telerik:RadTileView.ItemTemplate
>
<
telerik:RadTileView.ContentTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
telerik:RadTileView.ContentTemplate
>
</
telerik:RadTileView
>
</
telerik:RadDocumentPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
x:Name
=
"DockedSplitContainer"
InitialPosition
=
"DockedRight"
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Pane 1"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
Background
=
"Silver"
/>
</
telerik:RadPane
>
<
telerik:RadPane
Header
=
"Pane 2"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
x:Name
=
"Pane2Grid"
Background
=
"Silver"
HorizontalAlignment
=
"Center"
Loaded
=
"Pane2Grid_Loaded"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"0"
/>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"1"
/>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"2"
/>
</
Grid
>
</
telerik:RadPane
>
<
telerik:RadPane
Header
=
"Pane 3"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
Background
=
"Silver"
/>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
</
Grid
>
</
UserControl
>
Here is the code behind:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
Telerik.Windows.Controls;
namespace
DockingTest
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
this
.DataContext =
new
MainViewModel();
}
private
void
Pane2Grid_Loaded(
object
sender, RoutedEventArgs e)
{
if
(DockedSplitContainer.Parent
is
RadDocking &&
RadDockPanel.GetDock(DockedSplitContainer) == Dock.Right)
DockedSplitContainer.Width = Pane2Grid.ActualWidth;
}
}
}
In your sample code you are setting the Width of a root split container which should work correctly if the container is already initialized. Else its Width is set from the DockingPanel.InitialSize attached property. For more information on sizing SplitContainer you may refer to this article.
Kind regards,
Miroslav Nedyalkov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Please refer to the attached project that demonstrates the idea.
Kind regards,
Miroslav Nedyalkov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
This article gives more information about Unpinned panes. For setting their size you could use the AutoHideWidth and AutoHideHeight properties.
Hope this helps.
Regards,
Miroslav Nedyalkov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Here is the xaml:
<
UserControl
x:Class
=
"DockingTest.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadDocking
Background
=
"White"
>
<
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
>
<
telerik:RadPaneGroup
BorderThickness
=
"0"
>
<
telerik:RadDocumentPane
Visibility
=
"Collapsed"
CanUserClose
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
telerik:RadTileView
ItemsSource
=
"{Binding Items}"
>
<
telerik:RadTileView.ItemTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
telerik:RadTileView.ItemTemplate
>
<
telerik:RadTileView.ContentTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
</
telerik:RadTileView.ContentTemplate
>
</
telerik:RadTileView
>
</
telerik:RadDocumentPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking.DocumentHost
>
<
telerik:RadSplitContainer
InitialPosition
=
"DockedRight"
>
<
telerik:RadPaneGroup
>
<
telerik:RadPane
Header
=
"Pane 1"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
Background
=
"Silver"
/>
</
telerik:RadPane
>
<
telerik:RadPane
x:Name
=
"Pane2"
Header
=
"Pane 2"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
x:Name
=
"Pane2Grid"
Background
=
"Silver"
HorizontalAlignment
=
"Center"
Loaded
=
"Pane2Grid_Loaded"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"Auto"
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"0"
/>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"1"
/>
<
Rectangle
Width
=
"80"
Height
=
"80"
Fill
=
"Black"
Margin
=
"5"
Grid.Row
=
"2"
/>
</
Grid
>
</
telerik:RadPane
>
<
telerik:RadPane
Header
=
"Pane 3"
IsPinned
=
"False"
PaneHeaderVisibility
=
"Collapsed"
>
<
Grid
Background
=
"Silver"
/>
</
telerik:RadPane
>
</
telerik:RadPaneGroup
>
</
telerik:RadSplitContainer
>
</
telerik:RadDocking
>
</
Grid
>
</
UserControl
>
Here is the code behind:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
using
Telerik.Windows.Controls;
namespace
DockingTest
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
this
.DataContext =
new
MainViewModel();
}
private
void
Pane2Grid_Loaded(
object
sender, RoutedEventArgs e)
{
Pane2.AutoHideWidth = Pane2Grid.ActualWidth;
}
}
}
The problem is that when the pane content's Loaded event is fired, the value of the AutoHideWidth property is already used and the next time it is used is when the pane is shown again. Unfortunately setting the width to the popup element doesn't help as well as the animation is already started when the loaded event is fired and it overrides the width. This cannot be worked around only for initially unpinned panes which you'd like to be auto-sized and breaks only for the initial animation.
All the best,
Miroslav Nedyalkov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>