Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FrameworkElementExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using System.Windows;
9 using SiliconStudio.Presentation.Core;
10 
11 namespace SiliconStudio.Presentation.Extensions
12 {
13  public static class FrameworkElementExtensions
14  {
15  //public static async Task AwaitLoadedAsync(this FrameworkElement source)
16  //{
17  // if (source.IsLoaded == false)
18  // await new LoadedEventAwaiter(source);
19  //}
20 
21  // this is not an extension method because it is supposed to "extend" a method that is protected, so it has been made an helper method instead.
22  public static T CheckTemplatePart<T>(DependencyObject dependencyObject) where T : DependencyObject
23  {
24  if (dependencyObject == null)
25  return null;
26 
27  if ((dependencyObject is T) == false)
28  {
29  throw new ArgumentException(string.Format("Invalid '{0}' TemplatePart type. '{1}' expected.",
30  dependencyObject.GetType().FullName, typeof(T).FullName));
31  }
32 
33  return (T)dependencyObject;
34  }
35  }
36 }