0

I have the following code in XAML

<Button Tag='{Binding id}' Click="RecordClick">
                                            <Button.Template>
                                                <ControlTemplate>
                                                    <Image Source='./Images/RecordBG.png'  Height="270" Width="270" Margin='15,-5,0,0'/>
                                                </ControlTemplate>
                                            </Button.Template>
                                        </Button>

and in Code behind C#:

private void RecordClick(object sender, RoutedEventArgs e)
        {
            string buttonName = (string)((Button)sender).Tag;

            this.Frame.Navigate(typeof(QRChart),buttonName);
        }

When I click the Image button some part is not getting clicked. Some part is only working. I would like to know why it happens and how to fix this?

  • 1
    Marco's answer should work but, to understand why you're having the issue, is part of your image transparent? – keyboardP Apr 01 '13 at 13:23

2 Answers2

0

Try wrapping the presenter in a Border element with a set Background.

<ControlTemplate TargetType="{x:Type Button}">
    <Border Background="{TemplateBinding Background}">
    </Border>
</ControlTemplate>

Like:

    <Button Tag='{Binding id}' Click="RecordClick">
        <Button.Template>
            <ControlTemplate>
                <Border Background="image here"/></Border>
            </ControlTemplate>
         </Button.Template>
    </Button>
MeTitus
  • 3,390
  • 2
  • 25
  • 49
  • 1
    And have a look here: http://stackoverflow.com/questions/7541858/image-button-only-responds-when-clicking-on-the-image-and-not-the-area-around-in – MeTitus Apr 01 '13 at 05:07
  • @Margo x:Type not found error is coming. So I am unable to make use of the above code. –  Apr 01 '13 at 07:08
  • remove that you don't need it. my bad – MeTitus Apr 01 '13 at 07:10
0

I added Tapped event for the Texblocks which are present on top of the image. Now it is working as expected.