Adding text onto a custom keyboard in Xamarin Forms - c#

I'm in the midst of trying to create a custom keyboard using this guide https://medium.com/swlh/how-to-create-a-custom-keyboard-with-xamarin-forms-android-4fa3b83dad1d. The only problem I'm finding at the moment is that the way the element works only allows for Rows and Keys to be added, but I need to add some custom text to the section just above the keyboard, that could be defined in as a bindable property in the keyboard. Like so:
<local:EntryWithCustomKeyboard
x:Name="entry1"
HorizontalOptions="FillAndExpand"
LabelText="My text up here"
Margin="0, 0, 0, 20"
Keyboard="Text"
TextColor="Black"
Placeholder="Custom Keyboard entry..." />
To give this kind of result:
Does anyone have any suggestions on how this can be achieved?

Related

Button's Background in Xaml UWP

in a UWP application I have a button its Background property is set to "DeepPink", but whenever I hover my mouse over it, it changes to gray (the default color),
here is my code:
<Button Content="Hello World" Margin="100,0,0,0" Background="DeepPink"/>
Am I missing something??
That only defines the default state of the button, not the hover state.
You can either create a custom control template (you can see an example here), or go the easy way of changing colors with Lightweight styling - I'd recommend the second!
The best alternative would be to create Buttons like UI using Frame and Label. In this case, the background color will remain the same.
Example:
<Frame Padding="8" WidthRequest="100" HasShadow="False" BorderColor="Gray"
HorizontalOptions="Center">
<Label Text="Button" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>

Set Label HeightRequest automatically depending on how much space the text needs

I have a Label inside a StackLayout inside a Frame:
<Frame Grid.Row="0" Margin="0, 0, -10, 0" OutlineColor="Transparent" HasShadow="False" Grid.Column="1" BackgroundColor="{StaticResource rightBubbleColor}">
<StackLayout>
<Label
Style="{StaticResource rightBubbleStyle}"
TextColor="{StaticResource rightBubbleFontColor}"
Text="{Binding message}" />
</StackLayout>
</Frame>
This gives me this result:
The problem here is that the last message actually has more text which would need 6 rows to display the whole text.
If I set a value for HeightRequest for the Label, it changes the height of the Frame as well. For example if I set a value of 150, I get this result:
I need to dynamically set a value for HeightRequest depending on how much height the Text needs.
Does anyone know how I can achieve that (preferably in xaml) or is this even a wrong approach to my problem?
Edit 1:
Removing the style from the Label doesn't solve the problem. It only occurs on UWP. Note that I don't have a Windows Phone to test it, the problem occurs on my local machine (Windows 10 Desktop).
Edit 2:
According to the Xamarin documentation, the height should be autosized dependon on the content:
When the app developer sets the ListView.HasUnevenRows property to true, the behavior of the list view still depends on the ListView.RowHeight property. First, if the developer either does not set the ListView.RowHeight property or sets it to -1, list view items are autosized to fit their contents. This is the desired behavior and the intended use case for a ListView.HasUnevenRows value of true, as noted above.
I found a solution. This was the problem:
<RowDefinition Height="*" />
I set the value to Auto and now it's working. Strange that it has a different behaviour on iOS and Android tho.

How do I create a plus or minus button in my Windows Phone app using XAML?

I want to include a plus or minus button in my Windows Phone app. How can I change the content of the button to plus or minus?
<Button x:Name="buttonPlusOrMinus"
Content="+/-"
HorizontalAlignment="Left"
Margin="180,217,0,0"
Grid.Row="2"
VerticalAlignment="Top"/>
There is a few ways to do this.
Hold down the Alt key then type 0177 on the numpad and let go of Alt, this will cause you to type ±.
Open up the program charmap in windows, find the character you are looking for, then click the "Select" then the "Copy" button. You will then be able to paste the ± character in your code.
Copy the ± character from this question into your code.
<Button x:Name="buttonPlusOrMinus"
Content="±"
HorizontalAlignment="Left"
Margin="180,217,0,0"
Grid.Row="2"
VerticalAlignment="Top"/>
Windows 8 Dev Icons, Windows store app is the best app to meet all your requirements. You can simply copy and paste to make a + or - button as you want.
https://www.microsoft.com/en-us/store/apps/windows-8-dev-icons/9wzdncrdqhbv

Metro application directly focuses on my first field

I'm creating this test Metro application using Windows 8, VS2012, C# and XAML. There are different TextBox in the application page arranged in a StackPanel. When the application is launched the focus is on the first TextBox.
I was wondering how to "deactivate" this.
Here's a pic, as you can see the first field is focused (color changed and ToolTip displayed).
When your UI is loaded you can remove focus from the TextBox by applying a Programmatic focus state to any other control.
Imagine that you have a Button named myButton. You can:
myButton.Focus(FocusState.Programmatic);
You cannot however use FocusState.Unfocused state to remove focus from the TextBlock because it is not allowed and will throw an exception.
One simple fix for this is place something to catch it first with IsTabStop="True" with a 0 Opacity which is a bit hacky but the only way I know. So something like;
<TextBox IsTabStop="True" Opacity="0" Height="1" Width="1"/>
<!-- Then the rest of your content like your other TextBox stuff -->

WPF - Global Properties and User Controls

Greetings
I have a Main Window which will hold multiple User Controls. I will give you a better view with an example picture:
<!--Player 1-->
<local:ucRaces x:Name="ucRacesP1" Width="78" Height="33" Visibility="Hidden" />
<Image Name="imageRacePlayer1" Height="27" Width="27" />
<!--Player 2-->
<local:ucRaces x:Name="ucRacesP2" Width="78" Height="33" Visibility="Hidden" />
<Image Name="imageRacePlayer2" Height="27" Width="27" />
UC3 and UC4 are the same User Control
UC3 has been given the name ucRacesP1 (Hidden by default)
UC4 has been given the name ucRacesP2 (Hidden by default)
Depending on which button is pressed on the image one of these controls becomes visible.
Now what I want to do is, when a person selects a value in UC3 the properties for player1 need to be set. When a value gets selected in UC4 I need the properties for player2 to be set. I was thinking to do this with properties but when searching for Properties and WPF I stumbled upon Dependency Properties. Which started to confuse me a bit, would I need to use normal Properties or these Dependency Properties.
How can I know if I have to set the player1 values or the player2 values (this depends from which UserControl sends the data)?
How would I save these values best for the entire application?
Is putting the User Controls on hidden at the start (due to positioning) the best way or is there a better alternative?
Thank you for your time reading my question(s)!
i think , your statring point is
Depending on which button is pressed on the image one of these controls becomes visible
1- There are certain buttons on the image and user can click on the image.
2- You can make use of ICommand interface to exceute the specific command in UI i.e. if user press Palyer1 , you cna execute Player1Command if user presses Player2 , you can execute Player2Command.
3- There may be the duplication of code in player1 and player2 but don't worry about it , you can always refactor the code first thing is to dispatch the command to the respective command handler.

Categories