views:

192

answers:

1

Hi all, I have a simple button with some content. With my content though, the button click event doesn't fire if you click on it. You need to click on the small border (which is the button behind the content) to fire the event. What's the solution?

Thanks in advance.

<Button x:Name="btnAddFriend" Width="64" FontFamily="Fonts/Fonts.zip#Helvetica Neue LT Std" FontSize="10" Click="btnAddFriend_Click" Grid.Row="0" Grid.Column="3" HorizontalAlignment="Right">
    <Button.Content>
        <StackPanel Height="21" Width="62" Background="#FFC10708">
            <TextBlock Text="Add Friend" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,3,0,0" Width="58" />
        </StackPanel>
    </Button.Content>
</Button>

-- Update
Seems that the above code works fine in a brand spanking new silverlight project. So I'll have to provide more detail! The button is within a Grid, and that grid is within a tabcontrol. Now I've tried creating a new silverlight project with a copy and paste of the xaml and everything seems to work. But the problem is still happening on my actual project. I've cleared the browser caches umpteen times by now. I'm almost considering a new approach to my button.

+1  A: 

Sounds like you fixed your issue, but for future reference a good resource to solve these types of issues is Silverlight Spy. With Silverlight Spy you can open your Silverlight application and then walk through the UI tree and see visually on the screen what is going on. So in this case you would have seen that your button was hidden behind another element which was capturing the click event (actually the OnMouseLeftButtonDown event).

Bryant