Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

string format for percentage not working correctly

$
0
0

Hi ,

using string format for percentage but , my text show in correct value even if i enter correct value.

when i enter 2.00% then become red border for textbox. below code. tell me what wrong in code.

 Data objDat = new Data();
        public Window1()
        {
            InitializeComponent();
            this.DataContext = objDat;
        }
public class Data : INotifyPropertyChanged
    {
        public string Name {get; set;}
        public decimal amt { get; set; }
        public event PropertyChangedEventHandler PropertyChanged;
        public decimal Amt
        {
            get { return amt; }
            set
            {
                amt = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Amt"));
            }
        }
    }<Grid><Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="55,94,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/><TextBox Height="23" Text="{Binding Name}" HorizontalAlignment="Left" Margin="74,141,0,0" Name="textBox1" VerticalAlignment="Top" Width="120"  PreviewTextInput="textBox1_PreviewTextInput" FlowDirection="RightToLeft" KeyDown="textBox1_KeyDown" /><TextBox Height="23"  Text="{Binding Amt, UpdateSourceTrigger=PropertyChanged,StringFormat={}{0:N2}%,
                                                    Mode=TwoWay}"    HorizontalAlignment="Left" Margin="78,195,0,0"   Name="textBox2" VerticalAlignment="Top" Width="120" ></TextBox><Button Content="New" Height="23" HorizontalAlignment="Left" Margin="149,45,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" /></Grid>


Ashok



Viewing all articles
Browse latest Browse all 18858