I have a question about how bindings work in WPF.
If I have a viewmodel with this property:
private string testString;
public string TestString
{
get { return testString; }
set { testString = value; }
}
Then if I bind it to xaml with something like this:
<TextBlock
Text="{Binding Path=TestString, Mode=TwoWay}"
Foreground="Red"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="Calibri"
FontSize="24"
FontWeight="Bold">
</TextBlock>
It works ... Nothing new here.
However, if I remove the getters and setters from the test string and get something like this:
public string TestString;
The binding itself does not work. I do not know why this is happening, because for me it is equivalent to a public attribute of a public attribute with custom get and set.
Can someone shed light on this topic for me? :)
TYVM in advance!
PS: Sorry for my syntax. I just can't figure out how to work with a block of code.
Silva source
share