I got a small question for you. I am currently developing an application, based on Xamarin.Forms, and, on a ContentPage, i would like to always (yes i mean always always) show the keyboard. There is a textfield and some buttons or list, and when I click/tap on it, keayboard is hidden (and that is the standard behavior).
But here, I do not want if possible, to set the focus on the field for every action possible on the page. And even if I do that, we can see that the keyboard disappear and is shown back just after (trust me, me eyes are crying when it blink :)).
So, is it possible to set somewhere that we want to always show/display the keyboard ?
thanks a lot
Actually , it is not a good decision to keep the keyboard on the ContentPage , it will block other event like scroll and tap .
If you do want to implement it. You could define a default entry and set it onfocus when you finish editing other enrties .
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<Entry x:Name="defaultEntry" HeightRequest="0.1" WidthRequest="0.1" Unfocused="Entry_Unfocused" />
<Entry HeightRequest="100" WidthRequest="40" Unfocused="Entry_Unfocused" />
</StackLayout>
bool IsNeedShowKeyBoard=true ;
public MainPage()
{
InitializeComponent();
}
private void Entry_Unfocused(object sender, FocusEventArgs e)
{
if(IsNeedShowKeyBoard)
{
defaultEntry.Focus();
}
}
Change the property IsNeedShowKeyBoard to false when start to scroll or you want to edit other entry .
In fact, I will develop my own custom keyboard. With that solution, I will be able to let it be shown every time.
Related
I have two buttons. One is an edit button that when clicked allows the editing of other objects on the page. My hope is to have the second button appear only once this "edit state" has been initiated. That part isn't very difficult. However, I don't want to just alter the 1st button's alignment from right to left to make space for the 2nd button (a cancel button) to the 1st button's right - I want to animate this movement, as if to make it appear that the moving of the 1st button to the left, is uncovering the 2nd button.
I've been searching for hours trying to find out how to do this, and there's a multitude of options for WPF, but not many solutions for UWP applications.
So far, I've found this:
<Button x:Name="EoIdButton" Grid.Row="0" Grid.Column="2" view:EventHandlers.Attach="Click" BorderBrush="DarkGray" FontFamily="Segoe MDL2 Assets" Content="{Binding EoIdButtonContent, Mode=TwoWay, Converter={StaticResource SegoeConverter}}" Style="{StaticResource CircleButtonStyle}" Visibility="{Binding EoVis, Mode=TwoWay, Converter={StaticResource BooleanToVisibilityConverter}}">
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding SomeProperty, Mode=TwoWay}">
<core:ChangePropertyAction></core:ChangePropertyAction>
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
So, while I can change a property using this, I don't see how to create an animation. My guess, based on my searching would be to use a Storyboard, but again, most of the solutions I've found pertain to WPF and/or don't work because the scenario is too different. If someone has a solution for this, it'd be great.
For additionaly clarity
I have button 1:
(EditButton)
When (EditButton) is clicked, I want edit button to rendertransform/animate left and the result to look like so:
(EditButton)(CancelButton)
When either edit button or cancel button are clicked, I want it to return to the original state
I have a page with two text boxes, a check box and another two text boxes below at the bottom.
When I click on the check box, i want to set focus to the text box below it.
This works fine, the soft-keyboard appears and the screen scrolls up to reveal the text box above the keyboard.
However, if either TextBox1 or TextBox2 is currently in focus and the keyboard is already showing, setting focus from the CheckBox_Click event will reset the screen and it scrolls back down.
I'm guessing that the events clash with one another
- TextBox loses focus and hides the keyboard + scroll the screen back down
- TextBox got focus from outside and shows the keyboard (but doesn't scroll the screen up)
Can this be prevented somehow?
Here's a simplified version of the xaml and code
The xaml:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel Margin="0,100,0,0">
<TextBox x:Name="TextBox1" />
<TextBox x:Name="TextBox2" />
<CheckBox Content="Click Me" Click="CheckBox_Click" />
<TextBox x:Name="TextBox3" />
<TextBox x:Name="TextBox4" />
</StackPanel>
</Grid>
the code behind:
private void CheckBox_Click(object sender, RoutedEventArgs e)
{
TextBox3.Focus();
}
The problem you have is that the OS will try and move the page when the focus is on a control that isn't in a scrollable container and is obscured by the SIP.
I've worked around this by putting all the content in a ScrollViewer and adjusting the VerticalScrollOffset based on the selected control and if the SIP is shown or not. This was a lot of very messy, fiddely code. Ask yourself if the value of moving the focus is worth the effort before starting as there isn't a simple solution.
I've got a ListBox (dynamically populated via code):
(i can't insert the code, bah)
I need, with a button, to move this listbox vertically. The listbox have a fixed height, and also the items.
Can someone help me?
Per MSDN, it looks like this is a viable answer for you?
ListBox.ScrollIntoView Method
Edit - Comment Summary of Answer: The question here was targetting scrolling itself, not to a particular object. As such, the necessary action was to attain a reference to the ListBox's ScrollViewer. From there, a call needed to be placed to the ScrollViewer's ScrollToVerticalOffset method. As the OP wanted to scroll down a certain amount from the original position, the ScrollViewer's VerticalOffset property was incorporated into the call.
This works. Set the ListBox to not scroll, then add a ScrollViewer around it. Now in your code behind you can set the ScrollViewer to whatever you want.
XAML:
<!--Disable the ListBox scroll and add a ScrollViewer so we have control over the scroll position.-->
<ScrollViewer
Name="scrlvwrListBoxMessages"
VerticalScrollBarVisibility="Auto" >
<ListBox x:Name="lstbxMessages"
ScrollViewer.VerticalScrollBarVisibility="Disabled" >
</ListBox>
</ScrollViewer>
Code:
private void ScrollToBottom()
{
//Scroll to the bottom.
Dispatcher.BeginInvoke(() =>
{
this.scrlvwrListBoxMessages.ScrollToVerticalOffset(double.MaxValue);
});
}
Hi I want to create a looping listbox so that the last item's next item is the very first item and vice versa - creating a listbox that doesn't have a top or a bottom.
I know there is a LoopingSelector in the WP7 toolkit but it doesn't quite do what I want since it fades in/out peripheral items and you have a 'selected' item that is always in the middle.
I looked at the LinkedList collection but it doesn't seem to support looping: "The LinkedList(Of T) class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state."
Does anyone know a solution for what I'm looking for or would I need to develop a hybrid of the current Listbox and the toolkit's LoopingSelector?
Many thanx!
Take a look at Petzold's article on circular lists in MSDN Magazine.
I recently have a same problem as your! I use blend 4 to handle this, making my list reset to certain position at certain time, also adding a copy of a list in front and behind of the original list.
example: my list is: 1-2-3-4-5-6,
I would make it 1-2-3-4-5-6-1-2-3-4-5-6-1-2-3-4-5-6
and it reset to original position every 20sec. For example: if user was on item 4 it would reset the position to item 4 but at the middle list.
I currently have my question asking here you can check out if anything help:
horizontal listbox that could be infinite circle scrolling
Use Scrollviewer contains listbox, put manipulationCompleted event and use ScrolltoVerticalOffset(0) to have it looping scrolling. Maybe my code would help:
<ScrollViewer HorizontalScrollBarVisibility="Auto" Margin="-2,567,-1,0" x:Name="imagesScrollview"
Opacity="1" Grid.Row="1" RenderTransformOrigin="0.5,0.5"
ManipulationCompleted="imagesScrollview_ManipulationCompleted" Height="85" MouseLeftButtonDown="ScrollViewer_MouseLeftButtonDown">
<ScrollViewer.Background>
<ImageBrush ImageSource="/PhoneApp11;component/Images/top_friends_float.png" />
</ScrollViewer.Background>
<ListBox x:Name="listBox" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Width="Auto" Height="80" Background="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
and in Manipulation event:
private void imagesScrollview_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
ScrollViewer scrollviewer = sender as ScrollViewer;
if (scrollviewer.HorizontalOffset > (listBox.ActualWidth - 700))
scrollviewer.ScrollToHorizontalOffset(0);
else if (scrollviewer.HorizontalOffset < 100)
scrollviewer.ScrollToHorizontalOffset((listBox.ActualWidth - 487));
}
***Notice: I allow my scrollviewer to loop in both way.
I've been scouring the web looking for examples on how to handle flick gestures on Windows Phone 7 in the ViewModel using MVVM Light.
I've found some good resources on handling commands from button clicks and such, but I can't seem to find anything on how to handle gestures. Anyone know if this is possible? If so, are there any good resources or can you provide a quick example how this could be done?
If not, I guess I'll just have to break down and put code in the code-behind. Ugh, makes me sick thinking of it. ;)
You can use the GestureListenerEx from Wp7Tools.
Add Wp7Tools to your project:
PM> install-package wp7tools
In your xaml:
<Rectangle Fill="Red" Width="100" Height="100">
<toolkit:GestureService.GestureListener>
<wp7:GestureListenerEx
OnTapAction="Tap"
OnDragStartedAction="DragStart"
OnDragCompletedAction="DragEnd"
/>
</toolkit:GestureService.GestureListener>
</Rectangle>
And in your ViewModel:
public void Tap(GestureEventArgs e) {
//Do something
}
public void DragStart(DragStartedGestureEventArgs e) {
Debug.WriteLine(e.Direction);
}
public void DragEnd(DragCompletedGestureEventArgs e) {
Debug.WriteLine(e.Direction);
}
That's it. No code-behind, no commands, just point the method you want to be executed :)
How about making the control set you want to apply gestures to a user control?
Or even wrap a user control around the gesture listener then surface properties using dependency properties so you can bind to them