I have my Model as:
namespace Forecast.MVVM.WPF.ViewModel
{
public class ApplicationInfoViewModel
{
private string versionNumber;
public ApplicationInfoViewModel()
{
versionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
public string VersionNumber
{
get { return versionNumber; }
set { versionNumber = value; }
}
}
And my view I am setting the datContext and getting the values as ;
<UserControl .... xmlns:AppInfo="clr-namespace:Forecast.MVVM.WPF.ViewModel" .../>
<UserControl.Resources>
<AppInfo:ApplicationInfoViewModel x:Key="forecastVersionInfo"/>
</UserControl.Resources>
<Grid>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding VersionNumber}" VerticalAlignment="Bottom"/>
</Grid>
But I am unable to see the values
1st way :
Try tro replace
<UserControl.Resources>by<UserControl.DataContext>… and delete “
x:Key="forecastVersionInfo"“.2nd way :
Or set
DataContext="{StaticResource forecastVersionInfo}"on your textBlock.3rd way :
According to this MSDN page, set the Source property on your textblock binding :