I've a static class which reads information from the application assembly.
I've declared it static since the class needs no instance declaration and will only ever be read directly from, application-wide. I have a control with several labels that I would like to use to display some of this information.
How can I go about setting the controls DataContext equal to the class?
Code:
/// <summary>
/// Class for Reading Program Information.
/// </summary>
public static class ProgramInfo {
private static Assembly ProgramAssembly = Assembly.GetEntryAssembly( );
/// <summary>
/// Get Program Name
/// </summary>
public static string ProgramName {
get { return ProgramInfo.ProgramAssembly.GetCustomAttribute<AssemblyProductAttribute>( ).Product; }
}
/// <summary>
/// Get Program Build Date
/// </summary>
public static DateTime BuildDate {
get { return File.GetLastWriteTime( ProgramInfo.ProgramAssembly.Location ); }
}
/// <summary>
/// Get Program Version (Major.Minor)
/// </summary>
public static string Version {
get {
System.Version V = ProgramInfo.ProgramAssembly.GetName( ).Version;
return V.Major.ToString( ) + '.' + V.Minor.ToString( );
}
}
/// <summary>
/// Get Program Build (Build.Revision)
/// </summary>
public static string Build {
get {
System.Version V = ProgramInfo.ProgramAssembly.GetName( ).Version;
return V.Build.ToString( ) + '.' + V.Revision.ToString( );
}
}
}
XAML:
<UserControl x:Class="Tools.Controls.ProgramInformation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:pi="clr-namespace:Tools.Controls">
<UserControl.DataContext>
<pi:ProgramInfo/>
</UserControl.DataContext>
<!--Other Irrelevant Code-->
</UserControl>