WP7 Button inside ListBox only "clicks" every other press

Posted by Zik on Stack Overflow See other posts from Stack Overflow or by Zik
Published on 2012-04-06T23:06:00Z Indexed on 2012/04/06 23:30 UTC
Read the original article Hit count: 101

Filed under:
|

I have a button defined inside of a DataTemplate for my list box.

<phone:PhoneApplicationPage.Resources>        
    <DataTemplate x:Key="ListTemplate">
        <Grid Margin="12,12,24,12">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Button Grid.Column="0" Name="EnableDisableButton" 
                    Click="EnableDisableButton_Click" 
                    BorderBrush="Transparent">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Image Grid.Row="0" Source="\Images\img.dark.png" Width="48" Height="48" Visibility="{StaticResource PhoneDarkThemeVisibility}" />
                    <Image Grid.Row="0" Source="\Images\img.light.png" Width="48" Height="48" Visibility="{StaticResource PhoneLightThemeVisibility}" />
                    <Rectangle Grid.Row="1" Width="48" Height="8" Fill="{Binding CurrentColor}" RadiusX="4" RadiusY="4" />
                </Grid>
            </Button>

            <Grid Grid.Column="1">
              <... more stuff here ...>
            </Grid>
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

What I'm seeing is that the first time I press the button, the Click event fires. The second time I press it, it does not fire. Third press, fires. Fourth press, does not fire. Etc. Originally I had it bound to a command but that was behaving the same way. (I put a Debug.WriteLine() in the event handler so I know when it fires.)

Any ideas? It's really odd that the click event only fires every other time.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about windows-phone-7