locked
Right tap event for Grid item RRS feed

  • Question

  • Hi All,

    I am using a right tapped event for the controls inside a Grid. When I right click an item inside the grid, it changes it color and when I tap again, it restores its previous color(just for testing purpose).

    The problem I am facing is when I right click the first time, it changes the color as expected but when I do the same next time, it does not changes the color if there is an appbar used in the page. When I right tap the item next time(third tap event), then only the color gets changed. How to overcome this issue?

    what I need is if I right tap for the first time, it should open the appbar and the next right tap event should dismiss the appbar and change the color of the item. Can anyone help me in resolving this issue?


      <Grid Margin="120,0,0,0" x:Name="ContentHolder1" Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="200"/>
                    <RowDefinition Height="200"/>
                    
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"/>
                    <ColumnDefinition Width="200"/>              
                </Grid.ColumnDefinitions>
    
                <Rectangle Fill="Yellow" Grid.Row="0" Grid.Column="0" />            
                <Rectangle Fill="White" Grid.Row="1" Grid.Column="0" RightTapped="Rectangle_RightTapped_1"/>            
    
                <Rectangle Fill="Pink" Grid.Row="0" Grid.Column="1" />
                <Rectangle Fill="Maroon" Grid.Row="1" Grid.Column="1" />
    
            </Grid>

    <Page.BottomAppBar>
            <AppBar x:Name="BottomAppBar1" Padding="10,0,10,0" AutomationProperties.Name="Bottom App Bar" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50*"/>
                        <ColumnDefinition Width="50*"/>
                    </Grid.ColumnDefinitions>
                    <StackPanel x:Name="LeftPanel" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left">
                        <Button x:Name="Home" Tag="Home" Content="home" />
                    </StackPanel>              
                </Grid>
            </AppBar>
        </Page.BottomAppBar>

       private void Rectangle_RightTapped_1(object sender, RightTappedRoutedEventArgs e)
            {
                if (((Windows.UI.Xaml.Media.SolidColorBrush)((sender as Rectangle).Fill)).Color.ToString() != "#FF800080")
                (sender as Rectangle).Fill = new SolidColorBrush(Colors.Purple);
                else
                    (sender as Rectangle).Fill = new SolidColorBrush(Colors.Red);
            }

    • Edited by LearntoLearn Monday, September 16, 2013 8:19 AM added code
    Monday, September 16, 2013 8:14 AM

Answers

  • The second right-tap is for the light dismiss of the appbar.  This is by-design, and is expected behavior. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 16, 2013 1:57 PM
    Moderator
  • Hi Matt,

    I agree to that, that this should be the common behaviour.

    @LearnToLearn: If you don't want it to behave like this, just set the IsSticky-Property of the AppBar to true, then your Rectangle will also change the color everytime you right tap on it:

    <AppBar IsSticky="True"...>


    Thomas Claudius Huber

    "If you can´t make your app run faster, make it at least look & feel extremly fast"

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Monday, September 16, 2013 2:45 PM

All replies

  • The second right-tap is for the light dismiss of the appbar.  This is by-design, and is expected behavior. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 16, 2013 1:57 PM
    Moderator
  • Hi Matt,

    I agree to that, that this should be the common behaviour.

    @LearnToLearn: If you don't want it to behave like this, just set the IsSticky-Property of the AppBar to true, then your Rectangle will also change the color everytime you right tap on it:

    <AppBar IsSticky="True"...>


    Thomas Claudius Huber

    "If you can´t make your app run faster, make it at least look & feel extremly fast"

    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Monday, September 16, 2013 2:45 PM