Phone Number in Datagrid
-
1 พฤษภาคม 2555 11:08
Hi,
im displaying Phone Number in a Datagrid
<DataGridTextColumn Header="PHONE" Binding="{Binding Path=Phone}"/>all the numbers are showing as EX:123456789 from the DB
but i would like to show them in US format...
can anyone help me...
ตอบทั้งหมด
-
1 พฤษภาคม 2555 12:26
Hi Issac,
U can make use of "StringFormat" attribute which is available in WPF Bindings.
Please have a look at the link below explaining the same.
http://elegantcode.com/2009/04/07/wpf-stringformat-in-xaml-with-the-stringformat-attribute/
Hope it helps!
Please mark it as an answer if it resolves ur issue.
Regards, Parth Shah
- เสนอเป็นคำตอบโดย parth.shah 1 พฤษภาคม 2555 12:26
-
1 พฤษภาคม 2555 16:17
Hello Issac.
I actually use a converter for myprojects.
using System; using System.Windows.Data; namespace WpfApplication1 { public class PhoneConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double a = System.Convert.ToInt64(value); return a.ToString("(###) ###-####"); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } }And the xaml...
<Window.Resources> <local:PhoneConverter x:Key="PhoneConverter"/> </Window.Resources> <Grid x:Name="LayoutRoot"> <TextBox x:Name="textBox" HorizontalAlignment="Left" TextWrapping="Wrap" Text="5555555555" VerticalAlignment="Top" Margin="8,8,0,0" Width="104.193"/> <TextBlock x:Name="textBlock" Margin="8,58,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding Text, Converter={StaticResource PhoneConverter}, ElementName=textBox}" Width="104.193"/> </Grid>
This thread also addressed it or offered a solution... http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/476c28ad-fbcf-44f4-95c1-9b5deaa0742d
But I could never get the string FormatString to work properly, only the int32, which should be 64 for a US number, StringFormat.
~Christine
- แก้ไขโดย Christine L. _ 1 พฤษภาคม 2555 16:18
- ทำเครื่องหมายเป็นคำตอบโดย Issac999 2 พฤษภาคม 2555 8:17
-
2 พฤษภาคม 2555 5:31
Hi Issac,
The method suggested by Christine is also correct.
U can either make use of StringFormat attribute in WPF binding or u can also make use of Converter class as well.
Feel free to ask if u have any further queries.
Regards, Parth Shah
-
2 พฤษภาคม 2555 8:18thank u....worked perfectly for me......