.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > String format for Phone number
 

String format for Phone number

I am trying to format a listview that is bound to a datatable of phone numbers. I would like it to be (###)-###-#### I have had no success. I have written it in xaml as follows:
<ListView Name="lstPhone" Grid.Row="5" Height="100" ItemsSource="{Binding }">
                            <ListView.View>
                                <GridView >
                                    <GridViewColumn DisplayMemberBinding="{Binding Path=PHONE,StringFormat=\{0:(###)-###-#####\}}" Width="100" Header="Number"/>
                                </GridView>
                            </ListView.View>
                        </ListView>
  • Edited bybigbadvd37 Tuesday, September 22, 2009 4:12 PMCorrected code example
  •  
bigbadvd37
Because a phone number can be any string of numbers, with different formatting, I'd recommend actually making a custom IValueConverter that converts from a string to a custom class for phone numbers. This will provide a much better experience (and more control) than trying to do this with a numeric data type for phone number and a string formatter.


Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.
What is the data type of the PHONE property?
dekurver
Because a phone number can be any string of numbers, with different formatting, I'd recommend actually making a custom IValueConverter that converts from a string to a custom class for phone numbers. This will provide a much better experience (and more control) than trying to do this with a numeric data type for phone number and a string formatter.


Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.

You can use google to search for other answers

Custom Search

More Threads

• Toolbar problem - adding items from a control that doesn't "own" the toolbar
• WPF Images
• Numbered Lines and Text Wrapping
• where to put resource?
• ListView: How to keep cell content aligned to the top of the cell when row height increases?
• An expression blend (3D) question?
• data binding - pass parameter to converter
• the CellTemplate of GridViewColumn?
• WPF Datagrid - Need to select all checkboxes.
• Combobox in Listview ObjectdataProvider Error