Reputation: 335
I'm new to c# and wp development.
On "Holding" I want the Content value of the button as a string in my c# code.
<Grid>
<Pivot>
<PivotItem>
<Grid>
<Button x:Name="Venue1" Content="Venue1" HorizontalAlignment="Left" Margin="30,0,0,0"VerticalAlignment="Top" Width="342" Height="102" Grid.Row="1" Holding="Holding"/>
</Grid>
</PivotItem>
</Pivot>
</Grid>
I thought it was pretty straightforward and did this but doesn't work. TextToSpeech is a method that takes a string and reads it out. It reads out "Windows.UI.Xaml.Controls.Grid"... why?
private async void Holding(object sender, HoldingRoutedEventArgs)
{
await TextToSpeech(this.Content.ToString());
}
Upvotes: 1
Views: 671
Reputation: 9242
Try this :-
private async void Holding(object sender, HoldingRoutedEventArgs)
{
var obj = sender as Button;
var content = obj.Content;
await TextToSpeech(content);
}
What are you doing wrong is by using this. Here this does not belong to button but for the page itself. In place of this you have to use the corresponding button object that i have already shown how to use. For further reference see This Keyword
you can also use name of the button to get its content that is little bit hard coded.
Upvotes: 1
Reputation: 15006
It is pretty straightforward :)
await TextToSpeech(this.Venue1.Content.ToString());
Upvotes: 0