I have a stackpanel that contains an Image and a TextBlock. I\'m raising an event once double click is being performed by the user.(P.S - I\'m adding the St
You need to DataBind TextBlock
Text
(?) element to your class - like so:
In XAML
<TextBlock x:Name="MyTextBlock"
Text={Binding ShowThis, Mode=OneWay} />
in class:
public class MyDataContextClass
{
private string showThis = string.Enpty;
public string ShowThis
{
get {return showThis;}
set
{
showThis = value;
if (PropertyChanged != null)
PropertyChanged(....);
}
}
}
and you must DataBing Xaml to class. (May be in constructor ?)
public class MyXamlWindow
{
public MyXamlWindow()
{
this.DataContext = new MyDataContextClass();
}
}
There's a lot of ways to do all above
A simple way of getting the first child element of a certain type (e.g. TextBlock) is this:
var textBlock = panel.Children.OfType<TextBlock>().FirstOrDefault();
You either get the first TextBlock or null
if there isn't any.