How to format properties on custom Service Manager forms

Posted on Feb 8, 2016

When creating your own custom forms in Service Manager you may want to tweak your ListViews, especially when working with dates. For example you may want to hide time information for datetime properties. This is actually pretty simple by using BindingBase.StringFormat property

The below example shows a ListView definition containing two datetime columns both formatted to show date in the format ‘dd.MM.yyyy’ Properties do not necessary have to be bound to a ListVew column. Of course you can use StringFormat also to format text displayed in a TextBox for example.

    <ListView VerticalAlignment="Top" HorizontalAlignment="Stretch" x:Name="listViewInstances" MinWidth="450" MinHeight="250" ItemsSource="{Binding productinstance, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
    <ListView.View>
    <GridView>
    <GridViewColumn Header="Display Name"
    DisplayMemberBinding="{Binding DisplayName}"
    Width="Auto" />
    <GridViewColumn Header="Status"
    DisplayMemberBinding="{Binding status.DisplayName}"
    Width="Auto" />
    <GridViewColumn Header="Valid from"
    DisplayMemberBinding="{Binding validfrom, StringFormat='dd.MM.yyyy'}"
    Width="Auto" />
    <GridViewColumn Header="Valid until"
    DisplayMemberBinding="{Binding validuntil, StringFormat='dd.MM.yyyy'}"
    Width="Auto" />
    </GridView>
    </ListView.View>
    </ListView>