How Best to Do Something

Editors for WPF Forum

Posted 15 years ago by David Mullin
Version: 9.1.0500
Using the old DateTimePicker, I made a custom converter (for the ValueConverter property) so that I could display some extra calcualte information in the fields (for instance, the number of months since today).

What would be the best way to do this in the DateTimeEditBox? I originally thought that I would add a custom part to it and style it to be read only or somthing - but that looked like an aweful lot of work.

What seemed like a vastly easier way is to dynamically construct the Format property, and set it to something like "MM/dd/yyyy (12 \M\o\n\t\h\s)". This works perfectly, except for one problem - whenever the Format property changes, the control resets the focus to the first part of the control, which is really annoying (I trap the value changed event and calculate the format there). I tried to make it so that, if the control has focus, then I ignore the value change event - however, when moving between parts (which seems to be when the value is updated), IsFocused return false.

I'm really hoping that there is an easy way to do what I'm trying to do - needing to figure out how to build a custom part just for some dynamic display-only information is unfortunate.

David Mullin

Comments (2)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi David,

The PartEditBox (and thus DateTimeEditBox) can host any custom elements. So you can simply add a TextBlock to the control, whose Text property is bound to the DateTimeEditBox.Value and uses your custom converter.

Something like this:
<editors:DateTimeEditBox x:Name="editBox" Width="200" Margin="0,7,0,0" HorizontalAlignment="Left"
        Value="{x:Static system:DateTime.Today}" Format="d">
    <TextBlock editors:DateTimeEditBox.ItemPlacementSlot="Center" editors:DateTimeEditBox.ItemPlacementOrder="2"
            Margin="0,0,3,0" Foreground="{x:Static SystemColors.GrayTextBrush}" FontStyle="Italic"
            Text="{Binding Value, ElementName=editBox, Converter={StaticResource <<YOUR CONVERTER>>}}" />

Actipro Software Support

Posted 15 years ago by David Mullin
Absolutely brilliant!

I figured that there had to be an easy way to accomplish this - my experience of you is that you have things like this covered.


The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.