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

Set the stringformat of a datetime object in code behind.

$
0
0

I have the following code I worked on as an example of creating a binding dynamically for a GridView based on the object(s) that populate the ItemsSource.

    Private Sub SetUpTheColumns(firstObject As Object)
        Dim theClassProperties As PropertyInfo() = firstObject.GetType().GetProperties()
        Dim gv As GridView = theListView.View
        For Each pi As PropertyInfo In theClassProperties
            Dim columnName As String = pi.Name
            Dim grv As New GridViewColumn With {.Header = columnName}
            If pi.PropertyType Is GetType(DateTime) Then
                Dim i As Integer = 1
                Dim bnd As New Binding(columnName) With {.StringFormat = "{}{0:MM/dd/yyyy}"}
                'bnd.StringFormat = "{MM/dd/yyyy}"
                grv.DisplayMemberBinding = bnd
            Else
                grv.DisplayMemberBinding = New Binding(columnName)
            End If
            grv.DisplayMemberBinding = New Binding(columnName)
            gv.Columns.Add(grv)
        Next
        theListView.View = gv
    End Sub
End Class

The problem is with the StringFormat.  Nothing I put in takes.  I have looked at the binding using Snoop and there is no StringFormat for that column binding.  Everything else works great but the stringformat.

LS


Lloyd Sheen


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>