Monday, August 27, 2012

Childwindow re-size

Childwindow re-size

Hi,

 I have used a childwindow in my SIlverlight 4 website, my client wants the popups(childwindow) to be resizable, I tried but the content in the childwindow does not resize 

Please guide...

Answers & Comments...

Answer: 1

Hi Santosh

try this link

http://forums.silverlight.net/t/225042.aspx/1 or

In Xaml

<controls:ChildWindow x:Class="Export.ChildWindow1"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             Width="900"  Height="700"             Title="ChildWindow1">  

 or Set AUTO

Regards  KS Mani



 



Answer: 2

Hi,

Unfortunately, ChildWindow in Silverlight 4 don't support resizing. as S.manikandan mentioned, http://floatablewindow.codeplex.com/ is an good solution for resizing childwindow. But I don't agree with the solution he provide:

S.manikandan

In Xaml

<controls:ChildWindow x:Class="Export.ChildWindow1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" Width="900"  Height="700" Title="ChildWindow1">  

or Set AUTO

I have tested it, when I set the Widht and Height of ChildWindow as auto, I still can't resize ChildWindow, it not works.

Best Regards,



Answer: 3

Hi,

 Thank you for your reply but I have tried http://www.codeproject.com/Articles/121488/FloatingWindow-Multi-windows-Interface-for-Silverl

the problem with this is I have to add a 

FloatingWindowHost  
  to my MainPage, but anyways I found a way where I added the floatable window XAML directly and used visibility to manage it, but here I am unable to set the MinHeight or MinWidth it does not take effect, I tried the FloatableWindow_SizeChanged event but it not quit working the way it should 

Please suggest me a solution here...



Answer: 4

santoshf2

but here I am unable to set the MinHeight or MinWidth it does not take effect

Hi,

You sure the MinHeight and MinWidth doesn't work? I wrote an sample code to test it, it works for me. here is my code:

        private void Button_Click(object sender, RoutedEventArgs e)          {              FloatableWindow fw = new FloatableWindow();              fw.Title = "Show Date Time";              fw.Height = 200; fw.MinHeight = 150;              fw.Width = 300; fw.MinWidth = 250;              fw.Content = DateTime.Now.ToLocalTime();              fw.ShowDialog();          }  

When I drag the lower right corner of the popup to resize it, its height and width always greater than MinHeight and MinWidth.

Please let me know if you have any question.

Best Regards,



Answer: 5

Hi try this

in you child winow you add two button for maximize and minimize and in click even write this code . in this code when i click minimize button the child window will restore to its original position.

 private void MaximizeButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            xamlWidth = ((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(this)).Content)).ActualWidth + 22;
            xamlHeight = ((System.Windows.FrameworkElement)(((System.Windows.Controls.ContentControl)(this)).Content)).ActualHeight + 46;
            // get the explorer window size
            double height = Application.Current.Host.Content.ActualHeight;
            double width = Application.Current.Host.Content.ActualWidth;

            // need to make it a little bit smaller or it won't resize
            this.Height = height - 50;
            this.Width = width - 1;

            // need to update the layout here
            this.UpdateLayout();

            // the following code repositions the child window
            var root = VisualTreeHelper.GetChild(this, 0) as FrameworkElement;
            if (root == null)
            {
                return;
            }

            var contentRoot = root.FindName("ContentRoot") as FrameworkElement;
            if (contentRoot == null)
            {
                return;
            }

            var group = contentRoot.RenderTransform as TransformGroup;
            if (group == null)
            {
                return;
            }

            TranslateTransform translateTransform = null;
            foreach (var transform in group.Children.OfType<TranslateTransform>())
            {
                translateTransform = transform;
            }

            if (translateTransform == null)
            {
                return;
            }

            // reset transform
            translateTransform.X = 0.0;
            translateTransform.Y = 20.0;


        }

        private void MinimizeButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Height = xamlHeight == 0 ? 480 : xamlHeight;
            this.Width = xamlWidth == 0 ? 800 : xamlWidth;
                   

        }

 hope this will give you some idea



Answer: 6

Hi,

I have an question, what is your popup(child window)? An normal ChildWindow control or an FloatableWindow control?

As we talk before, the normal ChildWindow control in Silverlight 4 don't support resizing. But if you are using FloatableWindow control, you can try to do like this:

        FloatableWindow fw;          private double minWidth = 250d;      // MinHeight of fw          private double minHeight = 150d;     // MinWidth of fw            private void Button_Click(object sender, RoutedEventArgs e)          {              if (fw == null)                  fw = new FloatableWindow();              fw.Title = "Resize Child Window";              fw.Height = 200; fw.MinHeight = minHeight;              fw.Width = 300; fw.MinWidth = minWidth;                StackPanel panel = new StackPanel();              Button maxBtn = new Button();              Button minBtn = new Button();              maxBtn.Content = "Maximize Child Window";              minBtn.Content = "Minimize Child Window";              maxBtn.Click +=new RoutedEventHandler(MaximizeButton_Click);              minBtn.Click +=new RoutedEventHandler(MinimizeButton_Click);              panel.Children.Add(maxBtn);              panel.Children.Add(minBtn);                fw.Content = panel;              fw.ShowDialog();          }            private void MaximizeButton_Click(object sender, System.Windows.RoutedEventArgs e)          {          }            private void MinimizeButton_Click(object sender, System.Windows.RoutedEventArgs e)          {              //this.Height = xamlHeight == 0 ? 480 : xamlHeight;              //this.Width = xamlWidth == 0 ? 800 : xamlWidth;              fw.Width = fw.Width >= minWidth ? minWidth : fw.Width;              fw.Height = fw.Height >= minHeight ? minHeight : fw.Height;          }  

You can resize the popup (an FloatableWindow control) to original size by click the minBtn.

By the way, what do you want the MaximizeButton_Click method to do?

Hope that will be helpful.

Best Regards,





No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog