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

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

Related

How to highlight/select Clicked Character in Input Text Box?

In Visual Studio, C#, WPF, I have an input textbox with time format 00:00:00.000. Hours:Minutes:Seconds.Milliseconds.
When a 0 is clicked, it places the I-cursor next to it like normal. You must backspace the 0 and type the number you want. Or you can drag and highlight it manually.
I'm trying to simplify this process. How can I make it to where when you click a 0, it highlights just that one character, and when you type it overwrites it?
And is it possible to disable the colon and period from being selected, so they are not removed?
<TextBox x:Name="cutStart" HorizontalAlignment="Left" Height="22" Margin="415,129,0,0" TextWrapping="Wrap" Text="00:00:00.000" VerticalAlignment="Top" Width="75" IsEnabled="True" />

Add icon to button with Visual Studio

I have a simple question. I want to add an icon to a C# WPF Button control. I do not want to have to write C# code, or edit XAML to do this.
However, when I click on the button in the Designer, there is no option under properties to set an image. How do you do this through the Visual Studio GUI?
The easiest/best way to do this is to add an Image control as the Content of the Button.
The property window is somewhat limited in what it can do, and only supports text for that property. This does include bindings, so you could use an Image StaticResource. I couldn't find an easy way to create one from the property designer either though.
So basically, you are stuck with editing XAML. Either with a direct Content property or by creating an element in Resources Its not that bad! Just write:
<Button>
<Button.Content>
<Image ImageSource="..."/>
</Button.Content>
</Button>
Now of course, you could create a custom button that exposed that property via the designer, but thats even more XAML. Its WPF, you are going to have to write XAML, so learning how should be a priority.
Visual Studio 2015:
create a button.
create an image.
set the source of the image to the right file of your resources (e.g. a .png file that you included to your project)
drag the image over the button.
A text shows that asks you to press ALT to replace the text of the button with the image.
I currently don't know how to get both, image and text, for a button.
in XAML, it looks like this:
<Button x:Name="button12" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75">
<Image x:Name="image" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="24" Source="gfx/new.png"/>
</Button>
you could install FontAwesome on your Computer
Goto http://fontawesome.io and download. Open the downloaded ZIP file and inside the font folder there should be .otf file, Install that!
and in the content of the button you could simply type the desired icons code!
For eg:
if you want your button to look like this
then install FontAwesome Font
and in your button tag type Content="" FontFamily="FontAwesome"
More codes can be found here http://fontawesome.io/cheatsheet/

how to apply text watermark to text box in xaml (windows 8 metrro app)

I am workng on windows 8 app getting problem to use text watermark to text box, can anybody help me to find out how we can apply water mark init .
below is the code of my text box.
<TextBox x:Name="txtUserName" Width="351" Height="45" BorderBrush="Gray" BorderThickness="2" Background="{x:Null}"/>
Use
<TextBox Width="250" Name="_txtBox" PlaceholderText="Please enter CS#"/>
you can use Callisto toolkit for windows 8 it has watermark textbox control. you can install it from nuget package manager.
use this namespace in your page..
xmlns:CallistoControls="using:Callisto.Controls"
use the control like this.
<CallistoControls:WatermarkTextBox Watermark="Type to message" HorizontalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True" MaxHeight="100" Padding="5,5,20,30" />
there are other useful controls too. hope this helps you
There's no way to do it without using a third-party library or overriding the text box and creating your own "Watermark Text Box" class. You just listen for the got/lost focus events and display your text appropriately.
If you don't want to rely on 3rd party SDKs, you can create your own. Check out these tutorials.
Create Your First WinRT WatermarkTextBox Control
Watermark TextBox in Windows Store apps
WaterMarkTextbox Control in Windows Store Application Using XAML

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 -->

How to stop an (InputScope = Number) textbox from disappearing when it gains focus?

I have searched for other answers, but none are clear enough.
I have a problem where whenever I click on a textbox that I set the InputScope to "number", the number pad comes up but the box I was typing in disappears..
Here is a screenshot and my code.
(I am also overriding the light/dark theme on windows phone to do it)
<TextBox InputScope="Number" Height="72" HorizontalAlignment="Left"
Margin="159,190,0,0" Name="aTextBox" VerticalAlignment="Top" Width="227"
TextChanged="aTextBox_TextChanged" Foreground="Black" BorderThickness="0"
Background="White" />
Your problem appears to be that there is a different visual state for when the TextBox has input focus, which matches the phone theme you're trying to override. If you want to fight against the system theme, you'll need to retemplate the TextBox.
In Blend, in the Objects and Timeline window, right-click on the TextBox and select Edit Template | Edit a Copy...
In the dialog that appears, name your new style / template and where you want to create it in the XAML. Click OK.
You are now in template edit mode. (If you want to exit this mode, click the Return scope button at the top of the Objects and Timeline window)
Click on the States tab (or go to Window | States if not visible) and you can see all the different visual states for each mode of the TextBox (focused, unfocused, etc). As you click on each one, you'll see the TextBox in the designer change. Select each state and change the colors to what you want them to be.
Specifically, note how in the Focused state, the TextBox background becomes transparent by default. This is your issue. Change it to what you want it to be.
Finally, I want to recommend that you don't try to override the Light / Dark theme on Windows Phone, unless you are replacing it outright with your own branding / color scheme. It's a lot of work and it could annoy and confuse users who are used to seeing the theme they have chosen.
Good luck!
Try like this:
<TextBox Text="NumericTextBox">
<TextBox.InputScope>
<InputScope>
<InputScopeName NameValue="Number" />
</InputScope>
</TextBox.InputScope>

Categories