Resize a popup in WPF

Popup control has not build in support for resize. But we can do this by ourself. The following code,

Code Snippet

<Window

   x:Class=”ForumProjects.MainWindow”

   xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;

   xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;

   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;

        }

    }

}

WPF Group Box Style

Recently one of my client asked me to show a good looking group box for our application, so that after a 15 min research i decided to create a group box which will contains a banner at right corner of group box with nice appearance.

I thought it may be useful for others, so i have added this sample in Expression’s Gallery, if you like and wish to use that, download the style and use in your project.

Download Sample project from Here

Sample View:

WPF Group Box