Click here to Skip to main content
15,886,137 members
Articles / Desktop Programming / Windows Forms

FishEyePanel/FanPanel - Examples of custom layout panels in WPF

Rate me:
Please Sign up or sign in to vote.
4.84/5 (66 votes)
25 Sep 2006Ms-PL6 min read 297.6K   11.7K   215  
This article describes how to implement your own WPF layout panels like Grid and StackPanel.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace FanDemo
{
    /// <summary>
    /// Interaction logic for Favourites.xaml
    /// </summary>

    public partial class Favourites : Canvas
    {
        public Favourites()
        {
            InitializeComponent();
            this.close.MouseLeftButtonUp += new MouseButtonEventHandler(close_MouseLeftButtonUp);
            this.detailSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(detailSlider_ValueChanged);
        }

        FanPanel fan;

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            fan = (FanPanel)sender;
            fan.Refresh += new RoutedEventHandler(fan_Refresh);
            UpdateCount();
        }

        void OnClick(object sender, MouseButtonEventArgs e)
        {
            if (!fan.IsWrapPanel)
            {
                this.grid.Width = 660;
                this.grid.Height = 550;
                this.text.Visibility = Visibility.Collapsed;
                fan.IsWrapPanel = true;
                this.BeginStoryboard((Storyboard)grid.FindResource("expandPanel"));
            }
        }

        void close_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.Hide();
        }

        public void Hide()
        {
            fan.IsWrapPanel = false;
            detailSlider.Value = detailSlider.Maximum;
            this.BeginStoryboard((Storyboard)grid.FindResource("collapsePanel"));
        }

        void OnCompleted(object sender, RoutedEventArgs e)
        {
            if (!fan.IsWrapPanel && this.grid.Width != 230)
            {
                this.grid.Width = 230;
                this.grid.Height = 210;
                this.text.Visibility = Visibility.Visible;
                modal.Visibility = Visibility.Collapsed;
            }
        }

        void detailSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            int n = (int)(detailSlider.Value * 100 / detailSlider.Maximum);
            textDetail.Text = String.Format("DETAIL LEVEL: {0}%", n);
        }

        void fan_Refresh(object sender, RoutedEventArgs e)
        {
            UpdateCount();
        }

        void UpdateCount()
        {
            counter.Text = fan.Children.Count.ToString();
        }

        void OnItemClick(object sender, RoutedEventArgs e)
        {
            XmlDataProvider cvs = (XmlDataProvider)FindResource("Things");
            object o = cvs.Data;
            e.Handled = true;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Web Developer
Europe Europe
I am a principal development consultant at Microsoft in the UK specialising in UI development. Recently I've been doing a lot of WPF work including the BBC iMP project shown at MIX06. I've been developing software for over 20 years - VAX, WIN16, MFC, ASP.NET, WinForms, WPF.

My main hobby is cars and my favourite day out is at Thruxton race track driving the Porsche 911 Turbo.

Comments and Discussions