WPF NumberTextBox Allowing Decimals - wpf

I am having an issue with NumberTextBox. Below is the xaml code.
<cc:NumberTextBox
Margin="5,0,5,0"
HorizontalAlignment="Stretch"
IsEnabled="{Binding IsEditable}"
Style="{StaticResource TextBox_Default}"
TabIndex="25"
IsDecimalAllowed="True"
Text="{Binding ProductQuantity, ValidatesOnDataErrors=True, StringFormat={}{0:#.##}, UpdateSourceTrigger=PropertyChanged}" />
It should allow user to enter only 2 digits after the decimal. I tried to use StringFormat but it i snot working.
Example: 23.65567 it should allow user to enter only 23.65
Any suggestions to fix this issue.
Thanks in advance.

First of all, NumberTextBox is not a standard part of WPF. you should tag whatever library you are using for that element. then you will find more help here.
This link goes to a page where you can write your own NumberTextBox. As for digit limiting, just test for the "dot" and allow two more key-downs.
This link is an open source collection for numeric input control

Related

WPF Binding up and down the Visual Tree

From a control in a WPF XAML view, I need to access the properties of another control that I can reach in the Visual Tree only when walking up to a common parent control and then down from there.
As an example:
<PageUserControl>
<Grid>
<TextBlock Text="Some example text" />
</Grid>
<TextBlock Text="{Binding Source={RelativeSource Mode=FindAncestor, AncestorType=PageUserControl, Path=??? I want to access the TextBlock}" />
</PageUserControl>
I want to access the text property of the first text block from the second text block (this is just an example).
What I would need is a way to combine relative sources, first one to go up the visual tree and find the PageUserControl, second one to go down the visual tree from there and find the grid and then finally a third one to find the text block within the grid.
Am I missing something here or is it just not possible?
I cannot add control IDs or something like this, it has to work with control types only.
I was thinking about something like a relative source that takes a XPath syntax, but it seems as if this was meant for another purpose (binding XML documents).
Maybe another idea?
Thank you!
I found a solution for my problem. It is possible using this approach:
<PageUserControl>
<Grid>
<TextBlock Text="Some example text" />
</Grid>
<TextBlock Text="{Binding Path=Children[0].Children[0].Text,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=PageUserControl}}" />
</PageUserControl>
While not very flexible, it is good enough for me.

MaskedTextBox taking only integer

I am using MaskedTextBox.I want my textbox to take only digits upto 7 numerics.It should not take any special character like ,.##,so on....I tried with "ddddddd" as mask but it allows decimal.So t works for decimal only.also tried with 000000
can anybody suggest for correct Mask.
:MaskedTextBox x:Name="TxtTutionFees"
Grid.Row="1"
Width="78"
Height="23"
Margin="142,40,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AllowSign="False"
DecimalPrecision="2"
GroupNumerals="True"
InputMask="ddddddd"
IsEnabled="False"
PromptChar=" "
TextAlignment="Right"
GotFocus ="TextBox_GotFocus"/>
You can use MaskedTextBox from Extended WPF Toolkit.
If you will use this control your solution is following:
<xceed:MaskedTextBox x:Name="_maskedTextBox"
Mask="0000000"
ValueDataType="{x:Type s:Int32}" />
Where xceed and s are following namespaces:
xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:s="clr-namespace:System;assembly=mscorlib"
You could do this with an attached dependency property as in the answer Here. You can use this technique to filter out any characters that you don't want.

Silverlight stopped displaying text after certain number of characters

So I dont really touch or have touched silverlight programming but my company has this application built in it and I have a bug they want me to fix. The issue is my text box can hold up to about 778 characters or 16 rows but then you cant view anymore of what you wrote. If you copy all you get everything you wrote even though you might only see 3/4 of it. I am not sure what I need to do, if I need to create a control panel thing for over flow or set a max length, etc. What would be my best step for this? Any good ideas?
Code:
<TextBox HorizontalAlignment="Left" Name="txtDesc" Width="300" Height="80" Grid.Column="1" Grid.Row="0" TextWrapping="Wrap" Text="{Binding Path=ExcursionDescription, Mode=TwoWay, Converter={StaticResource StripNonAsciilCharacters1}}" VerticalScrollBarVisibility="Auto" Margin="0,0,5,0"/>

WPF show small number beside all Controls

I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something allowing me to show a small number besides every one control.
Some text ³
I came with the idea to write a MarkupExtension, where I could write that number like this:
..
<TextBlock Text="Some Text" SomeExtension="3" />
..
and then to add it somehow to the template of the Control.
But I'm sure, you guys have better solution for this problem ;)
One way to go with it would be create a Attached Property. Upon setting it on a control, a custom Adorner would be added for that control showing specified number.
Use the tag property to provide the number you want and inside the custom template databind to the property
<TextBlock Text="Some Text" Tag="3" />
and inside the controltemplate
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}"/>

Tools\addin's for formating or cleaning up xaml?

I'm guessing these don't exist since I searched around for these but I'm looking for a few tools:
1) A tool that cleans up my xaml so that the properties of elements are consistent through a file. I think enforcing that consistence would make the xaml easier to read. Maybe there could be a hierarchy of what comes first but if not alphabetical might work.
Example before:
TextBox Name="myTextBox1" Grid.Row="3" Grid.Column="1" Margin="4"
TextBox Grid.Column="1" Margin="4" Name="t2" Grid.Row="3"
Example after:
TextBox Name="myTextBox1" Grid.Row="3" Grid.Column="1" Margin="4"
TextBox Name="t2" Grid.Row="3" Grid.Column="1" Margin="4"
(note < /> has been remove from the above since control seem to have issues parsing whe the after section was added)
2) Along the same lines as above, to increase readability, a tool to align properties, so from the above code example similar props would start in the same place.
<TextBox Name="myTextBox1" Grid.Row="3" Grid.Column="1" Margin="4"/>
<TextBox Name="t2" Grid.Row="3" Grid.Column="1" Margin="4"/>
I know VS has default settings for XAML documents so props can be on one line or separate lines so maybe if there was a tool as described in (1) this would not be needed...but it would still be nice if you like your props all on one line.
3) A tool that adds X to the any of the Grid.Row values and Y to any of the Grid.Column values in the selected text. Every time I add a new row\column I have to go manually fix these. From my understanding Expression Blend can help with this but seem excessive to open Blend just to increment some numbers (and just don't grok Blend). Maybe vs2010 with the designer will help but right now I'm on VS08 and Silverlight.
Any one know of any tools to help with this?
Anyone planning to write something like this...I'm looking at you JetBrains and\or DevExpress.
Thanks.
Try out Kaxaml. It has a couple auto-formatting tools like this.

Resources