I have a label in WPF4 and trying to bind the content to a value from c# class. I have created an ObjectDataProvider but for some reason can’t see the content or updates. Can you point me to what I’m doing wrong?
Here is the xaml –
<Grid.Resources>
<local:SummaryData x:Key="mySummaryData"/> </Grid.Resources>
<Label Name ="lbCurrentVerValue" Grid.Row="1" Grid.Column="2" Content="{Binding Path=frameworkVersion, Source={StaticResource mySummaryData}}"/>
<TextBox Name ="lbFromVerValue" Grid.Row="2" Grid.Column="2" Text="{Binding Source={StaticResource mySummaryData}, Path=frameworkVersion}"/>
and here is the c# code-
namespace DBUpgradeUI
{
public partial class DBUpgReadinessCheck : Window
{
public string userConnStr = String.Empty;
public string userFoldPath = String.Empty;
public SummaryData sd = new SummaryData();
public DBUpgReadinessCheck()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ReadinessCheck(userConnStr, userFoldPath);
}
public void ReadinessCheck(string connectionString, string folderPath)
{
FrmImportUtility frmWork = new FrmImportUtility();
sd.frameworkVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); ;
frmWork.CurrentlyProcessingVersion(connectionString, folderPath, ref sd.currentVersion, ref sd.finalVersion);
}
}
public class SummaryData
{
public string currentVersion = "Test";
public string finalVersion = "finalVerTest";
public string frameworkVersion = String.Empty;
}
}
After trying ways to bind properties from a class object without having dependency properties and having no luck, I have done the following and it works like a charm!
xaml –
and c# code –
This works great. Thanks everyone for your help.