Skip to content

Instantly share code, notes, and snippets.

@DarrenHurst
Created November 23, 2012 02:56
Show Gist options
  • Save DarrenHurst/4133822 to your computer and use it in GitHub Desktop.
Save DarrenHurst/4133822 to your computer and use it in GitHub Desktop.
Custom UIControl with UIPopUP C# Metro
using System;
using Windows.UI.ViewManagement;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;
using Windows.UI.Xaml.Controls;
using Windows.UI.Core;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml;
using Windows.Foundation;
using Windows.UI.Xaml.Media;
using System.Reflection;
namespace Metro.Utils
{
public class UIPopUp<T> where T : UserControl, new()
{
public async void PopUpMessage(string text)
{
MessageDialog msg = new MessageDialog(text, "");
await msg.ShowAsync();
}
public delegate void ShowDialogEvent();
public static event ShowDialogEvent showDialog;
public bool isDialogRequest;
public bool _isDialogRequest
{
get
{
return isDialogRequest;
}
set
{
isDialogRequest = value;
if (showDialog != null)
showDialog();
}
}
public void showDialogPopup()
{
_isDialogRequest = true;
}
public void callDialog(Page pg)
{
if ((pg.Dispatcher != null) && (!pg.Dispatcher.HasThreadAccess))
{
pg.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
new DispatchedHandler(() =>
{
Popup popupWindow = new Popup();
UserControl ctrl = new T();
var windowBounds = Window.Current.Bounds;
var rootVisual = Window.Current.Content;
GeneralTransform gt = pg.TransformToVisual(rootVisual);
var absolutePostition = gt.TransformPoint(new Point(0, 0));
ctrl.Measure(new Size(Double.PositiveInfinity, double.PositiveInfinity));
popupWindow.IsLightDismissEnabled = true;
popupWindow.Child = ctrl;
popupWindow.IsOpen = true;
})).AsTask().Wait();
}
}
}
}
@DarrenHurst
Copy link
Author

Create an Instance of UIPopUp

UIPopUp control = new UIPopUp

T = any Metro Custom UserControl

control.callDialog(this);

Event

control.showDialog += method

@DarrenHurst
Copy link
Author

Sorry

UIPopUp control = new UIPopUp

@DarrenHurst
Copy link
Author

UIPopUp (T) conrol = new UIPopUp(T)
() = greater/lessthan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment