Get value inside the 'ContentControl' of a button

1

I have the following code in XAML :

<Button Grid.Column="0" Grid.Row="1" x:Name="btnSete" Click="btn_Click">
    <ContentControl>
        <Viewbox Margin="3">
            <TextBlock Text="7"/>
        </Viewbox>
    </ContentControl>           
</Button>

and no code behind:

private void btn_Click(object sender, RoutedEventArgs e)
{
    Button btn = (Button)sender;
    //txbDisplay.Text = btn.ContentStringFormat.ToString();
}

Doubt is now, how do I in the event of Click get the content that is within:

<ContentControl>
    <Viewbox Margin="3">
        <TextBlock Text="7"/>
    </Viewbox>
</ContentControl>

button?

I want to show in txbDisplay the value that is in <TextBlock Text="7"/> .

    
asked by anonymous 06.04.2015 / 14:47

1 answer

1

I was able to resolve it as follows:

I removed <ContentControl>

<Button Grid.Column="1" Grid.Row="2" x:Name="btnCinco" Click="btn_Click">
    <Viewbox Margin="3">
        <TextBlock Text="5"/>
    </Viewbox>
</Button>

and in the event I did so:

private void btn_Click(object sender, RoutedEventArgs e)
{
    Button btn = (Button)sender;

    var viewBox = (Viewbox)btn.Content;
    var txtBlock = (TextBlock)viewBox.Child;
    var text = txtBlock.Text;

    txbDisplay.Text += text;
}
    
06.04.2015 / 17:52