Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an event for CustomDialog (IsOpenChanged) #243

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Callisto.TestApp/SamplePages/CustomDialogSample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
x:Class="Callisto.TestApp.SamplePages.CustomDialogSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Callisto.TestApp.SamplePages"
xmlns:callisto="using:Callisto.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Margin="100,50,0,0" HorizontalAlignment="Left">
<TextBlock FontSize="14.6667" FontWeight="Bold" Text="Click below to launch a custom dialog" />
<Button Content="Custom Dialog" Click="CustomDialogClicked" />
<StackPanel Orientation="Horizontal">
<Button Content="Custom Dialog" Click="CustomDialogClicked" />
<TextBlock x:Name="IsOpenChangedTextBlock" Text="" FontSize="18" />
</StackPanel>
<Button Content="Message Dialog (System)" Click="MessageDialogClicked" />

<Button Content="Test Memory Leaks" Click="CustomDialogTestForMemoryLeak" />
</StackPanel>
</Grid>
</Page>
</Page>
44 changes: 18 additions & 26 deletions src/Callisto.TestApp/SamplePages/CustomDialogSample.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Callisto.Controls.Common;
using LinqToVisualTree;
using UIElementLeakTester;
using Windows.Foundation;
using Windows.Foundation.Collections;

using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Callisto.Controls.Common;
using Callisto.Controls;
using Windows.UI;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
using Callisto.Controls;

namespace Callisto.TestApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class CustomDialogSample : Page
public sealed partial class CustomDialogSample
{
private CustomDialog dialog;

public CustomDialogSample()
{
this.InitializeComponent();

this.Loaded += (sender, args) => {
var mp = Frame.Ancestors<Frame>().FirstOrDefault().Descendants<Page>().FirstOrDefault();
dialog = (mp as MainPage).LoginDialog;
dialog.IsOpenChanged += (o, e) => {
IsOpenChangedTextBlock.Text = (bool)e.NewValue ? "Open" : "Closed";
};
};
}

private void CustomDialogClicked(object sender, RoutedEventArgs e)
{
var mp = Frame.Ancestors<Frame>().FirstOrDefault().Descendants<Page>().FirstOrDefault();
(mp as MainPage).LoginDialog.IsOpen = true;
dialog.IsOpen = true;
}

private void MessageDialogClicked(object sender, RoutedEventArgs e)
{
MessageDialog md = new MessageDialog("Bacon ipsum dolor sit amet bacon ham drumstick strip steak, sausage frankfurter tenderloin turkey salami andouille bresaola. Venison salami prosciutto, pork belly turducken tri-tip spare ribs chicken strip steak fatback shankle tongue boudin andouille. Meatloaf salami pork ground round turkey jerky meatball ball tip, filet mignon fatback flank prosciutto shank. Turkey boudin ham hock, filet mignon tri-tip bresaola tongue venison spare ribs meatloaf flank beef pancetta. Leberkas turducken flank ground round biltong chuck bacon kielbasa. Beef pastrami meatball, short loin venison swine pork loin shank meatloaf spare ribs.",
MessageDialog md = new MessageDialog(
"Bacon ipsum dolor sit amet bacon ham drumstick strip steak, sausage frankfurter tenderloin turkey salami andouille bresaola. Venison salami prosciutto, pork belly turducken tri-tip spare ribs chicken strip steak fatback shankle tongue boudin andouille. Meatloaf salami pork ground round turkey jerky meatball ball tip, filet mignon fatback flank prosciutto shank. Turkey boudin ham hock, filet mignon tri-tip bresaola tongue venison spare ribs meatloaf flank beef pancetta. Leberkas turducken flank ground round biltong chuck bacon kielbasa. Beef pastrami meatball, short loin venison swine pork loin shank meatloaf spare ribs.",
"Bacon Terms and Conditions");

#pragma warning disable 4014
md.ShowAsync();
#pragma warning restore 4014
}

private void DialogCancelClicked(object sender, RoutedEventArgs e)
{
//TaggedDialog.IsOpen = false;
}

/// <summary>
/// To ensure there is no memory leak, a new CustomDialog is added to and removed from the visual tree.
/// Each step waits for it to load before continuing.
Expand Down
12 changes: 9 additions & 3 deletions src/Callisto/Controls/CustomDialog/CustomDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)

#region Events
public event RoutedEventHandler BackButtonClicked;
public event DependencyPropertyChangedEventHandler IsOpenChanged;
#endregion

#region Member Variables
Expand Down Expand Up @@ -120,13 +121,18 @@ public bool IsOpen

private static void OnIsOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
var dlg = d as CustomDialog;
if (dlg != null)
{
CustomDialog dlg = d as CustomDialog;
if (dlg != null)
if ((bool)e.NewValue)
{
dlg.ApplyTemplate();
}

if (dlg.IsOpenChanged != null)
{
dlg.IsOpenChanged(d, e);
}
}
}

Expand Down