views:

2581

answers:

6

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.

+1  A: 

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.

Soviut
A: 

Well stackoverflow doesn't seem to like me pasting in the whole page. It apparently trys to render it as html...

At any rate there isn't much to it. It is just the standard namespaces, a grid, and the textblock and button inside the grid.

A: 

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

A: 

I have the exact same problem - it's kind of dumb how it doesn't work. must be a silverlight bug.

A: 

I have exact same problem the code is as simple as it can be. clean silverlight project xaml -

<UserControl x:Class="SilverlightApplication2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
    <Button Width="100" Height="30" Content="Click" Click="Button_Click" />
    <TextBlock x:Name="txt1" Text="Start" />
</Grid>
</UserControl>

the only thing that button doing is update that textblock. not woking. if I replace them it's work. Look like a bug...

A: 

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.

Akash Kava