I have a class which contain 3 strings
e.g.:
class abc
{
public string a, b, c;
public abc(string d, string e, string f)
{
a = d;
b = e;
c = f;
}
};
private void button1_Click(object sender, RoutedEventArgs e)
{
abc obj = new abc("abc1","abc2","abc3");
var MainPage1 = new MainPage();
MainPage1.DataContext = obj;
}
and when I try to bind to a textblock it doesn’t bind
<TextBlock Height="23" HorizontalAlignment="Left" Margin="201,66,0,0" Name="textBlock1" **Text="{Binding Path=a}"** VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="201,107,0,0" Name="textBlock2" **Text="{Binding Path=b}"** VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="201,156,0,0" Name="textBlock3" **Text="{Binding Path=c}"** VerticalAlignment="Top" />
I think I am missing something, but need help to find it. thanks
From MSDN: The data binding engine supports public properties, sub-properties, as well as indexers, of any common language runtime (CLR) object.
So use properties instead of public fields:
Now you can set it as the
DataContexte.g. in your MainPage’s constructor: