1
votes

I have a silverlight page with a textblock and button on it. Like this:

<TextBlock x:Name="txbNote" Margin="50,50" Text="Hello"/>        
<Button x:Name="btnCheck" Height="40"  Click="btnCheck_Click" ClickMode="Press" Margin="50,50,50,50" Content="Check Service"/>

Here is the handler for the click event:

Private Sub btnCheck_Click(ByVal sender As Object, ByVal e As EventArgs) 'Handles btnCheck.Click
  txbNote.Text = "I Was Clicked"
End Sub

It works... but... Why doesn't this work?

<Button x:Name="btnCheck" Height="40"  Click="btnCheck_Click" ClickMode="Press" Margin="50,50,50,50" Content="Check Service"/>
<TextBlock x:Name="txbNote" Margin="50,50" Text="Hello"/>        

The only change is the relative position of the textblock and button. The button's click event (and every other event I tried) just doesn't fire unless the textblock is before the button in the xaml.

3

3 Answers

1
votes

You may need to post more code as this could be an issue with the surrounding tags, such as the container that these controls are in.

If you're unable to paste it all to StackOverflow, use www.dpaste.com or www.pastebin.com.

0
votes

If you place these elements in the Panel instead of the Grid, it starts working.

0
votes

As you mentioned grid, if you placed two items in grid, the last item is on the top in hierarchy, all top level events are received by TextBlock, you should create two columns in grid and put items in individual columns.