UWP XAML Windows Phone Dialog issue with soft Keyboard - xaml

I've developed an app, as soon as the user enters a username and password and continues I display a dialog with a selection of buttons for the user to choose. As there is a login screen, the keyboard is displayed. I've hooked into the Enter button so that it is the same as tapping the Sign In button - this is where I hit issues.
IF the dialog is shown whilst the keyboard is active, the dialog content size is not full screen (despite the keyboard disappearing). But if the Sign In button is tapped (i.e. keyboard is not active) everything is fine.
The images below probably explain things better.
I'm not sure what to do to resolve this - any ideas?
FYI - I can scroll the buttons but only in that top section of screen.

As always - I ask a question and then find the answer.
When I catch the "Enter button tapped" event, I set focus to the page. It's a bit of a hack as I'd rather know why the issue is happening and stop it altogether instead of just dealing with it, but it works...
this.Focus(FocusState.Keyboard);// this is the line that solves it.
Full code:
private void tbPassword_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
this.Focus(FocusState.Keyboard);
StartLogin();
}
}

#Rick have a good way.But I have other good way that you can make the keyboard show and UWP can arrange the UI.
You can use InputPane.GetForCurrentView().TryHide() to hide the keyBoard and use InputPane.GetForCurrentView().TryShow() to show the keyBoard. So you can hide it when you want to show the ContentDialog.
But I have not think it is a good way.
You can use InputPane.GetForCurrentView().Showing to know when is the keyBoard is Showed and use InputPane.GetForCurrentView().Hiding to know when hide the keyBoard .
First,you can make the Grid with a row is show keyBoard when show keyBoard it will get the Hight.
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition x:Name="HightKeyboard" Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
When the keyBoard be showed ,you can use e.OccludedRect.Height get the keyBoard's height.
InputPane.GetForCurrentView().Showing += (s, e) =>
{
HightKeyboard.Height=new GridLength(e.OccludedRect.Height);
};
And you should make the row height hide when hide the keyBoard.
InputPane.GetForCurrentView().Hiding += (s, e) =>
{
HightKeyboard.Height=new GridLength(1);
};
You can show the UI in the first Row ,and when the keyBoard show the height above will be arrange.

Related

How to prevent Esc key from light dismissing a popup?

I have a Popup which needs to be light dismissed when user taps an element outside the popup. By default, pressing the Esc key also triggers LightDismiss, which I would like to prevent. Instead, I'd like to handle this KeyDown event explicitly.
Handling the Tapped event in the page's root to check if user's tapped outside the popup is one solution, but since every tap in my app will go through this, I'd prefer not to take this approach.
Some pseudo-code:
<Page>
<Grid>
<Popup
x:Name="FooTip"
Opened="FooTip_Opened"
Closed="FooTip_Closed"
IsLightDismissEnabled="True"
ShouldConstrainToRootBounds="True">
<!-- Popup content here -->
</Popup>
</Grid>
</Page>
TLDR: FooTip should not get light dismissed when Esc key is pressed.
FooTip should not get light dismissed when Esc key is pressed.
You could handle the PreviewKeyDown event for the Page like this:
private void OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Escape
&& FooTip.IsOpen)
{
e.Handled = true;
}
}

How to make a default button in UWP app using XAML?

I'm trying to declare a button as default in UWP app but receive an error:
The property 'IsDefault' was not found in type 'Button'
How can I make a default button in UWP app?
I down know what IsDefault is in WPF but to get if a button is pressed in UWP you can use CoreWindow.GetForCurrentThread().KeyDown. Create a Method that will be called from when the button is pressed or VirtualKey.Enter is clicked.
public MainPage()
{
this.InitializeComponent();
CoreWindow.GetForCurrentThread().KeyDown += MainPage_KeyDown; ;
}
private void MainPage_KeyDown(CoreWindow sender, KeyEventArgs args)
{
switch (args.VirtualKey)
{
case Windows.System.VirtualKey.Enter:
// handler for enter key
break;
default:
break;
}
}
You can use key down event which you can place on any textbox for example if you are making a login page then probably there will be 2 textboxes for username and password then just add key down event handler to textbox as it will be the last mandatory field like this:
<PasswordBox KeyDown="PasswordKeyDown"/>
then you can handle this event as:
using System.Windows.Input;
private void PasswordKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
Login();
}
Hope it will help you :)
There is not easy or clean way to solve your problem because IsDefault is not available for uwp apps.
if you are using MVVM or you want to reuse your code I recommend you to use Behaviors and follow the examples that the other guys posted.
I need a Button which user can invoke by pressing the ENTER key.
In an UWP app, by default a Button can be invoked by pressing the Enter key. So I guess what you want is setting the focus on this Button when there are some other UIElements in your page.
You can refer to Keyboard navigation among UI elements,
By default, the tab order of controls is the same as the order in which they are added to a design surface, listed in XAML, or programmatically added to a container.
To focus on the Button which is not the first element, you can just give the TabIndex="1" property to your Button, this property can make your Button get focus whenever the page is loaded, but if you change the focus on other controls in this page, you will need to reselect this button by mouse clicking, touching or TAB key.

Tool Tip obscures button

I want to pop up a tool tip when mouse moves over button, to explain what will happen if the user clicks on the button.
This code seems to do the job ( except for a big snag )
wxHelpProvider::Set(new wxSimpleHelpProvider);
...
btnDisplay = new wxButton( this, -1,
"DISPLAY", wxPoint(10,35));
btnDisplay->SetHelpText("Click to display this dimension");
btnDisplay->Bind( wxEVT_ENTER_WINDOW, &cHiddenDimensionPanel::OnDisplayHelp, this );
...
void cHiddenDimensionPanel::OnDisplayHelp(wxMouseEvent& event)
{
wxHelpProvider::Get()->ShowHelp((wxWindowBase*)event.GetEventObject());
}
The snag is that the tooltip obscures the button! If I click on it, the tool tip vanishes for a moment, but immediately pops back up. It is not possible to click the button under the tooltip.
You should be using the SetToolTip(const wxString &tipString) method, and letting wx handle showing/hiding the tooltip - not re-appropriating the HelpText property and manually managing the tooltip display.

Custom context menu XAML for WP8

I try to implement a custom ContextMenu in a LongListSelector.
I'm not using the ContextMenu from Microsoft.Phone.Controls.Toolkit, it's basically the same as in the Rowi App:
(source: hiddenpineapple.com)
Approach 1
My list item toggles a VisualState on hold and an overlay is shown with controls in it.
The problem
I can't find a way to go back to the default state when the user clicks outside of the list item (as in the default ContextMenu).
Approach 2
I've implemented a custom template for the toolkit ContextMenu which looks exactly the same. I had to move its margin top to -itemHeight, as by default it is below the item.
The problem
The problem with this solution is, that it automatically closes itself when opening and I couldn't figure out how to avoid this.
Another problem was that it didn't work well with TiltEffect.IsTiltEnabled from the Toolkit (visual problems).
I need your help
Any suggestions on how to get this working?
Answer
Thanks to Cheese, now I know how to properly close the menu when the user clicks outside.
His suggestion was to get the coordinates of a Tap event on the current page, and check if it's inside the menu. When not, close the menu.
So I added a Tap listener to the page when the menu opens, and removed it when the menu closes. From the page listener I got the event coordinates and could check if it's inside the control which holds the menu (same size and position). I received the position of the control with Point leftUpperPoint = control.TransformToVisual(page).Transform(new Point(0, 0)) and the rightLowerPoint by adding the ActualWidth and ActualHeight.
But then I realized:
Why should I even calculate if the tap is inside the menu? I always want to close the menu when the user taps anywhere on the screen. If it's outside, yes. If it's on a menu button, yes.
Another modification I made was to listen for MouseLeftButtonDown instead of Tap as it also triggers when the user swipes.
So I removed this code and came up with the following:
private void ToggleMenu(object sender, System.Windows.Input.GestureEventArgs e)
{
PhoneApplicationFrame frame = ((PhoneApplicationFrame)Application.Current.RootVisual);
VisualState state = this.States.CurrentState;
if (state == null || state.Name == "DefaultState")
{
frame.MouseLeftButtonDown += MouseDownDelegate;
this.State = "MenuState";
}
else
{
frame.MouseLeftButtonDown -= MouseDownDelegate;
this.State = "DefaultState";
}
}
private void MouseDownDelegate(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToggleMenu(sender, null);
}
This works perfectly!
Thanks to Cheese for the hint.
Something like this by #denniscode http://dotnet.dzone.com/articles/rowi-show-tap-menu
Approach 1 problem
The best solution would be:
Get the menus coordinates, when user makes a tap - you check are tap coordinates on menu or not, if not - dissmiss - simple.
Approach 2 problem
I guess you had some button in a corner and when you tapped on it - nothing happened? And when you dissmissed the Tilt all worked. It seems that tilt works faster than a click, so, tilt changes the button coordinates, and device thiks you have missed/or dragged off
You can use what #ScottIsAFool suggested and maybe create another Dependency Property on your TapMenu control of type UIElement named CloseWhenTappedElement and automatically listen for Tap events inside your control once set. For example
<Grid x:Name="TapArea"/>
<TapMenu CloseWhenTappedElement="{Binding ElementName=TapArea"}/>

How do you utilize the flipview and make a "selection" by tapping or clicking the screen?

In Win 8, the flipview control is a great control to browse the collection. But how or what is the best way to make a "selection" with a tap or a mouse click? I can always put a button outside of the flip view, but that's not the touch experience that everyone of a tablet would expect.
can someone give some example code (XAML/C#) of how to setup a flipview control with a selection of some sort that would navigate to a totally different page?
I wrote some sample code that works, if I'm understanding the question correctly. I am able to swipe through the FlipView and tap the individual item:
<FlipView Tapped="FlipView_Tapped_1">
<Image Source="Images/Apple.jpg" />
<Image Source="Images/Orange.jpg" />
<Image Source="Images/Banana.jpg" />
</FlipView>
And then
private YourTypeHere SelectedItem;
private void FlipView_Tapped_1(object sender, TappedRoutedEventArgs e)
{
this.SelectedItem = (sender as FlipView).SelectedItem;
}
You might not want to set a field, but you get the idea. Hopefully, you will be setting something in your view model. From there you can nav away or anything you need. A FlipView inherits from ItemsControl just like every other XAML repeater. So you can treat it exactly the same. http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.aspx