andrew4582

WindowTitleExtentsions WPF

Jul 22nd, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1.  
  2. namespace System.Windows {
  3.  
  4.     public static class WindowTitleExtentsions {
  5.  
  6.         public static void SetTitle(this Window w,string s = "",bool includeBuildDate = false) {
  7.             w.Title = includeBuildDate ? GetTitleWBuildDate(s) : GetTitle(s);
  8.         }
  9.  
  10.         public static string GetTitleWBuildDate(string s = "") {
  11.             //"M/d/yyyy h:mm:ss:ffff"
  12.             //string nt = AboutAssembly.Current.Title + " -  " + AboutAssembly.Current.Version.ToString();
  13.             string nt = string.Format("{0} - {1}",
  14.                 AboutAssembly.Current.Title,
  15.                 AboutAssembly.Current.Version);
  16.            
  17.             if(!string.IsNullOrWhiteSpace(s))
  18.                 nt += " - " + s;
  19.            
  20.             string Build_Fmt = "ddd, MMM/dd/yyyy h:mm tt";
  21. #if DEBUG
  22.             Build_Fmt = "ddd, MMM/dd/yyyy h:mm:ss tt";
  23. #endif
  24.             nt += string.Format(" - Built on {0}",
  25.                 AboutAssembly.Current.BuildDate.ToString(Build_Fmt));
  26.  
  27.             return nt;
  28.         }
  29.         public static string GetTitle(string s = "") {
  30.             string nt = string.Format("{0} - {1}",
  31.                 AboutAssembly.Current.Title,
  32.                 AboutAssembly.Current.Version);
  33.            
  34.             if(!string.IsNullOrWhiteSpace(s))
  35.                 return nt + " - " + s;
  36.             else
  37.                 return nt;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment