DateTimeEditBox

Editors for WPF Forum

Posted 13 years ago by Maria Brinas-Dobrowski
Version: 11.1.0543
Avatar
Hi - We are using the DateTimeEditBox and whenever we do ctrl + A, it selects the date, great! but I want to insert the contextmenu of the (select all, copy, cut, paste) for our user.

so, I did the below code:

    <ContextMenu x:Key="TextBoxContextMenu" Background="White">
          <MenuItem Command="ApplicationCommands.Copy" />
          <MenuItem Command="ApplicationCommands.Cut" />
          <MenuItem Command="ApplicationCommands.Paste" />
                  <MenuItem Command="ApplicationCommands.SelectAll" />
        </ContextMenu>
        <ControlTemplate x:Key="ShowContextMenu" TargetType="{x:Type Editors:DateTimeEditBox}">
            <Grid>
                <Editors:SlottedItemsPresenter x:Name="PART_ItemsPresenter" ContextMenu="{StaticResource TextBoxContextMenu}" d:IsLocked="True"/>
                <Popup x:Name="PART_Popup"/>
            </Grid>
        </ControlTemplate>
this works in some way..
but there are several challenges that I encounter and I wonder if you know the answer to my problems.

- select all command is disable and yet you can do, ctrl+A and will do the same thing
- when I select the whole date (by ctrl+A) and do right click its losing the selection

any suggestions?

Thanks!

Comments (9)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Maria,

The selection of the entire date/time is a special mode we added. This doesn't appear to work well with context menus, because the focus is shifting when the context menu is shown/hidden. This causes the control to drop out of this special mode. I've marked down a TODO item to see about adding better context menu support when the part group (i.e. date/time) is selected in the future.

Currently, you'd have to use custom commands that operate directly on the DateTimeEditBox instead. For example, a custom copy command could take the current DateTimeEditBox.Value and put it on the clipboard.


Actipro Software Support

Posted 13 years ago by Maria Brinas-Dobrowski
Avatar
Ok. I will try your suggestion.

What about turning off the tabstop in the part of day and year?
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Maria,

You should be able to use implicit Styles to accomplish that. Something like:
<editors:DateTimeEditBox ...>
    <editors:DateTimeEditBox.Resources>
        <Style TargetType="editors:DateTimeMonthPart">
            <Setter Property="IsTabStop" Value="False" />
        </Style>
        <Style TargetType="editors:DateTimeDayPart">
            <Setter Property="IsTabStop" Value="False" />
        </Style>
    </editors:DateTimeEditBox.Resources>
</editors:DateTimeEditBox>


Actipro Software Support

Posted 13 years ago by Maria Brinas-Dobrowski
Avatar
I tried the above code, but for some reason it is not working.
Did you try this on your end? Maybe I am missing something out.

<Editors:DateTimeEditBox Grid.Column="1"
                                 Grid.Row="0"
                                 IsNullAllowed="True"
                                 Value="02/02/2002" Template="{DynamicResource ShowContextMenu}">
            <Editors:DateTimeEditBox.Resources>
                         <Style  TargetType="{x:Type Editors:DateTimeMonthPart}" >
                             <Setter Property="IsTabStop" Value="False" />
                        </Style>
                         <Style TargetType="Editors:DateTimeDayPart">
                            <Setter Property="IsTabStop" Value="False" />
                        </Style>
            </Editors:DateTimeEditBox.Resources>
       </Editors:DateTimeEditBox>

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Maria,

Sorry, looks like the parts are not tab stops by default. Their default control templates include a MaskedTextBox, which is a tab stop.

So you'd need to use this instead:
<editors:DateTimeEditBox.Resources>
    <Style x:Key="{x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}"
            TargetType="{x:Type editors:MaskedTextBox}"
            BasedOn="{StaticResource {x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}}">
        <Setter Property="IsTabStop" Value="False" />
    </Style>
</editors:DateTimeEditBox.Resources>
You could bind the MaskedTextBox's IsTabStop to the part (using a RelativeSource and AncestorType). But then you'd need to set IsTabStop to true where appropriate, instead of setting it to false.


Actipro Software Support

Posted 13 years ago by Maria Brinas-Dobrowski
Avatar
Great! That works!
Posted 13 years ago by Maria Brinas-Dobrowski
Avatar
So, I've been playing with IsTabStop property (see below ) but this setting affects the function of the property IsFocusMovedOnTerminalMatches under editors:DateTimeEditBox.
Pretty much what is happening when I enter my date like my first digit of my month, it will jump right away to my next control... Is this a down-side of wanting a tabstop off?

<Setter Property="IsTabStop"
                          <Style x:Key="{x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}"
                       TargetType="{x:Type editors:MaskedTextBox}"
                       BasedOn="{StaticResource {x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}}">
                    <Setter Property="IsTabStop"
                            Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type editors:DateTimeEditBox}}, Path=IsTabStop}" />

                  
                </Style>
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Maria,

Yes, that would be a problem. The IsFocusMovedOnTerminalMatches moves the focus to the next focusable/tabstop control. So if you turn off the tabstops, then the focus won't be moved to them on terminal matches.


Actipro Software Support

Posted 13 years ago by Maria Brinas-Dobrowski
Avatar
That's kind of a bummer.

For anybody like us who needs a function like this...
here's my workaround..

- create a custom control and inherit the DateTimeEditBox
- override the KeyDown event and add the below code


            bool currentValue = (e.Key == Key.Tab);
            
            IsTabStop = !currentValue;
            IsFocusMovedOnTerminalMatches = IsTabStop ;

- in the resource dictionary you have to make sure that your styling is covered your custom control
- and you will still need the styling of the maskedtextbox that you will see on this discussion thread.

[Modified at 08/24/2011 08:58 AM]
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.