How does one simply "Databind a textblock to a codebehind C# variable"?
In my codebehind I have a public string variable and in my XAML I have but it does not work.
Thanks in advance!
How does one simply "Databind a textblock to a codebehind C# variable"?
In my codebehind I have a public string variable and in my XAML I have but it does not work.
Thanks in advance!
Use the BindingOperations
class. Something like this.
BindingOperations.SetBinding(myTextBlock, TextBlock.TextProperty, new Binding("Whatever"))
Without knowing more about what you're trying to bind, this is the best answer you'll get.
And it's almost always better to use a real MVVM pattern rather than to do this sort of thing in codebehind.