-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to a common base class for all user controls
Issue #14
- Loading branch information
Showing
8 changed files
with
49 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,18 @@ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls; | ||
using SirenOfShame.Uwp.Ui.Views; | ||
|
||
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236 | ||
|
||
namespace SirenOfShame.Uwp.Ui.Controls | ||
{ | ||
public sealed partial class Leaders | ||
{ | ||
public Leaders() | ||
{ | ||
this.InitializeComponent(); | ||
InitializeComponent(); | ||
} | ||
|
||
private void ListViewBase_OnItemClick(object sender, ItemClickEventArgs e) | ||
{ | ||
var page = FindParent<Page>(); | ||
page.Frame.Navigate(typeof(ViewUser)); | ||
} | ||
|
||
private T FindParent<T>() where T : FrameworkElement | ||
{ | ||
return FindParent<T>(this); | ||
} | ||
|
||
private T FindParent<T>(FrameworkElement element) where T : FrameworkElement | ||
{ | ||
if (element == null) return default(T); | ||
var parent = element.Parent as FrameworkElement; | ||
var parentAsT = parent as T; | ||
if (parentAsT != null) | ||
return parentAsT; | ||
return FindParent<T>(parent); | ||
Navigate<ViewUser>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
|
||
namespace SirenOfShame.Uwp.Ui.Controls | ||
{ | ||
public class UserControlBase : UserControl | ||
{ | ||
private T FindParent<T>() where T : FrameworkElement | ||
{ | ||
return FindParent<T>(this); | ||
} | ||
|
||
private T FindParent<T>(FrameworkElement element) where T : FrameworkElement | ||
{ | ||
if (element == null) return default(T); | ||
var parent = element.Parent as FrameworkElement; | ||
var parentAsT = parent as T; | ||
if (parentAsT != null) | ||
return parentAsT; | ||
return FindParent<T>(parent); | ||
} | ||
|
||
protected void Navigate<T>() | ||
{ | ||
var page = FindParent<Page>(); | ||
page.Frame.Navigate(typeof(T)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters