|
using System;
using System.Collections.Generic;
using System.Linq;
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.Threading;
using Tabber3D;
namespace Tabber3D_TestApp
{
/// <summary>
/// Demonstrates using the <see cref="TabPanel3D">TabPanel3D</see>
/// to show the current FrameworkElement in a popup window (PopupWindow.xaml).
/// This should only be used for non interactive elements, as the events for the interactive
/// elements will be in a different VisualTree if using a new Window to host the
/// current FrameworkElement.
///
/// This also demostrates using the <see cref="TabPanel3D">TabPanel3D</see> in a standalone manner.
/// Ie, the <see cref="TabPanel3D">TabPanel3D</see> is not part of an ItemsControl.
/// </summary>
public partial class PopupTestWindow : Window
{
#region Ctor
public PopupTestWindow()
{
InitializeComponent();
tabPanel3D.SelectedElementChanged +=
new SelectedElementChangedEventHandler(tabPanel3D_SelectedElementChanged);
this.LoadCodeBasedItems();
this.Closing += new System.ComponentModel.CancelEventHandler(PopupTestWindow_Closing);
}
#endregion
#region Private Methods
/// <summary>
/// On close un-hook from tabPanel3D.SelectedElementChanged event
/// </summary>
private void PopupTestWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
tabPanel3D.SelectedElementChanged -= tabPanel3D_SelectedElementChanged;
}
/// <summary>
/// Use the <see cref="TabPanel3D">TabPanel3D</see> SelectedElement to show
/// on PopupWindow.xaml
/// </summary>
private void tabPanel3D_SelectedElementChanged(object sender, SelectedElementChangedEventArgs e)
{
////Show Window for current image
FrameworkElement fe = tabPanel3D.Children[e.SelectedElement] as FrameworkElement;
PopupWindow pw = new PopupWindow();
pw.Title = "Selected Picture";
pw.Closed += new EventHandler(PopupWindow_Closed);
tabPanel3D.DisconnectLogicalChild(fe);
pw.CurrentContent = fe;
pw.ShowDialog();
}
/// <summary>
/// When the PopupWindow.xaml is closed, re-add its contained FrameworkElement
/// back to the <see cref="TabPanel3D">TabPanel3Ds</see> Logical children
/// </summary>
private void PopupWindow_Closed(object sender, EventArgs e)
{
// See modified CurrentContent property
// must remove the framework element so that it no longer has a logical parent
PopupWindow pw = sender as PopupWindow;
FrameworkElement fe = pw.CurrentContent;
pw.CurrentContent = null;
pw.Closed -= PopupWindow_Closed;
tabPanel3D.ReconnectLogicalChild(fe);
}
/// <summary>
/// Load some images
/// </summary>
private void LoadCodeBasedItems()
{
AddImage("images/image01.jpg");
AddImage("images/image02.jpg");
AddImage("images/image03.jpg");
AddImage("images/image04.jpg");
AddImage("images/image05.jpg");
AddImage("images/image06.jpg");
}
/// <summary>
/// Creates and adds a single image
/// </summary>
/// <param name="uri">image uri</param>
private void AddImage(string uri)
{
//Create a Focusable Border that contains the Image
tabPanel3D.Children.Add(new Border
{
Child = new Image
{
Source = new BitmapImage(new Uri(uri,
UriKind.RelativeOrAbsolute))
},
BorderBrush = Brushes.White,
BorderThickness = new Thickness(2)
});
}
#endregion
}
}
|
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.
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)
- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence
Both of these at Sussex University UK.
Award(s)
I am lucky enough to have won a few awards for Zany Crazy code articles over the years
- Microsoft C# MVP 2016
- Codeproject MVP 2016
- Microsoft C# MVP 2015
- Codeproject MVP 2015
- Microsoft C# MVP 2014
- Codeproject MVP 2014
- Microsoft C# MVP 2013
- Codeproject MVP 2013
- Microsoft C# MVP 2012
- Codeproject MVP 2012
- Microsoft C# MVP 2011
- Codeproject MVP 2011
- Microsoft C# MVP 2010
- Codeproject MVP 2010
- Microsoft C# MVP 2009
- Codeproject MVP 2009
- Microsoft C# MVP 2008
- Codeproject MVP 2008
- And numerous codeproject awards which you can see over at my blog