Question

I have this text inside a XAML that I want to change from "123ABC" to "456DEF".

<TextBlock x:Name="driverStatusValue" HorizontalAlignment="Left" Margin="205,45,0,0" Grid.RowSpan="2" TextWrapping="Wrap" Text="123ABC" VerticalAlignment="Top" Foreground="#FFA4C400"/> 

I have this function that shows a messagebox, I also want this function to change the x:Name="driverStatusValue" to change. How? I can't find anything that could help me with this in the Windows Phone API documentation.

private void drive_click(object sender, EventArgs e)
{
   MessageBox.Show("Text changed!");
}
Était-ce utile?

La solution

To change the text of your control, just access the control by its name and change the Text property:

private void drive_click(object sender, EventArgs e)
{
   this.driverStatusValue.Text = "456DEF";
}

As to change the Name property, although I think it would be technically possible, I can't think of a single situation where that would be a good idea. The name is used to identify a control, therefore you're not supposed to change it at runtime. Why would you want to do that?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top