Search code examples
c#wpfdata-bindingversion-numbering

Is it possible to bind a TextBlock's Text to an applications AssemblyVersion?


If I have a TextBlock in the corner of my UserControl is it possible to bind the Text property to my Assembly Version Number Which is in AssemblyInfo.cs

WPF:

<TextBlock Text="{Binding AssemblyVersion}"/>

AssemblyInfo.cs

[assembly: AssemblyVersion("1.0.0.0")]

Solution

  • Create a readonly property named AssemblyVersion and bind it.

    public Version AssemblyVersion
    {
        get
        {
            return Assembly.GetEntryAssembly().GetName().Version;
        }
    }