How Best to Do Something

Editors for WPF Forum

Posted 10 years ago by David Mullin
Version: 9.1.0500
Avatar
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 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
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>>}}" />
</editors:DateTimeEditBox>


Actipro Software Support

Posted 10 years ago by David Mullin
Avatar
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.

Thanks!

David
The latest build of this product (v2018.1 build 0675) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.