Answered by:
How we can handle the Popup PointerPressed event?

Question
-
I am trying to capture the Mouse actions in WinRT application. I can able to get the mouse actions through PointerPressed event in page for all child elements (Page). But, that not working for Popup and that child elements. How we can capture Popup child action in root (Page)?
I tried PointerPressed event with Popup. That is also not working.
<UserControl
x:Class="WinRTTestApp.UserControlTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Border Background="White" HorizontalAlignment="Stretch">
<Grid x:Name="rootGrid" Height="Auto" Background="Transparent">
<Grid>
<Popup x:Name="popupBlock" HorizontalAlignment="Right" HorizontalOffset="-300" IsOpen="True" Visibility="Visible">
<Popup.ChildTransitions>
<TransitionCollection>
<PaneThemeTransition Edge="Right" />
</TransitionCollection>
</Popup.ChildTransitions>
<Border BorderThickness="0" Background="#1f0068" x:Name="popupBlockBorder" Height="600" HorizontalAlignment="Center" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" >
<TextBlock Margin="15" Text="PopupTextBox" Foreground="White" FontSize="25" FontFamily="Segoe UI Light"/>
</Grid>
<Grid Background="Transparent" x:Name="popupContentBlock" Grid.Column="0" Grid.Row="1" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
<Grid Grid.Row="2" Height="Auto" >
<Button x:Name="View" Content="View" Background="#233f8c" Foreground="White" Margin="20,0,0,0" Width="120" BorderThickness="1" BorderBrush="White"/>
<Button x:Name="Cancel" Content="Cancel" Background="#233f8c" Foreground="White" Margin="170,0,0,0" Width="120" BorderThickness="1" BorderBrush="White"/>
</Grid>
</Grid>
</Border>
</Popup>
</Grid>
</Grid>
</Border>
</UserControl>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace WinRTTestApp
{
public sealed partial class UserControlTest : UserControl
{
public UserControlTest()
{
this.InitializeComponent();
this.popupBlock.PointerPressed += popupBlock_PointerPressed;
}
void popupBlock_PointerPressed(object sender, PointerRoutedEventArgs e)
{
// Not firing
}
}
}
- Edited by Lingaraj S Wednesday, March 4, 2015 5:23 PM Typo mistake..
Wednesday, March 4, 2015 5:17 PM
Answers
-
Hi Lingaraj S,
Based on your description, I know that you want to capture Popup child action. Then a quick workaround is to handle the PointerPressed event of the popupBlockBorder, so please to modify your code as following:
>>How we can capture Popup child action in root (Page)?
public sealed partial class UserControlTest : UserControl { public UserControlTest() { this.InitializeComponent(); popupBlockBorder.PointerPressed += popupBlockBorder_PointerPressed; } void popupBlockBorder_PointerPressed(object sender, PointerRoutedEventArgs e) { popupBlockBorder.Background = new SolidColorBrush(Colors.Red); } }
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- Proposed as answer by Mankdng Nef Thursday, March 5, 2015 10:16 AM
- Edited by Amy PengMicrosoft employee, Moderator Thursday, March 5, 2015 10:20 AM
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Wednesday, March 18, 2015 7:10 AM
Thursday, March 5, 2015 10:15 AMModerator
All replies
-
Hi Lingaraj S,
Based on your description, I know that you want to capture Popup child action. Then a quick workaround is to handle the PointerPressed event of the popupBlockBorder, so please to modify your code as following:
>>How we can capture Popup child action in root (Page)?
public sealed partial class UserControlTest : UserControl { public UserControlTest() { this.InitializeComponent(); popupBlockBorder.PointerPressed += popupBlockBorder_PointerPressed; } void popupBlockBorder_PointerPressed(object sender, PointerRoutedEventArgs e) { popupBlockBorder.Background = new SolidColorBrush(Colors.Red); } }
Best Regards,
Amy Peng
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
- Proposed as answer by Mankdng Nef Thursday, March 5, 2015 10:16 AM
- Edited by Amy PengMicrosoft employee, Moderator Thursday, March 5, 2015 10:20 AM
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Wednesday, March 18, 2015 7:10 AM
Thursday, March 5, 2015 10:15 AMModerator -
Yes, as Amy Peng described, if you want to hanld the child action of the Popup control, you have to capture the popupBlockBorder PointerPressed event .
Vote if help you
- Edited by Mankdng Nef Thursday, March 5, 2015 10:27 AM
Thursday, March 5, 2015 10:26 AM