Today and Clear button in DateTimeEditBox

Editors for WPF Forum

Posted 10 years ago by Azhagiri Selvam
Version: 10.1.0522
Avatar
Hi Actipro Team,

Previously we were using DateTimePicker and currently we have upgraded to DateTimeEditBox. In DateTimePicker, we had two properties TodayButtonVisible and ClearButtonVisible to show/hide Today and Clear button respectively.

Do we have something like that in DateTimeEditBox too?

I read in a post here that it can be achieved by applying Styles but it didn't provide any insight into how it can be done. It would be helpful if you can post a sample code for getting Today and Clear buttons.

Thanks in advance,
Giri

Comments (10)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Giri,

These properties are called IsTodayButtonVisible and IsClearButtonVisible on the MonthCalendar. The DateTimeEditBox exposes the MonthCalendarStyle property, which is applied to the MonthCalendar used in the drop-down. So you can use a Style like the following and assign it to the MonthCalendarStyle of your DateTimeEditBox. Or you can create an implicit Style for the DateTimeEditBox that assigns the MonthCalendarStyle.
<Style x:Key="MyMonthCalendarStyle" TargetType="editors:MonthCalendar">
    <Setter Property="IsClearButtonVisible" Value="True" />
    <Setter Property="IsTodayButtonVisible" Value="True" />
</Style>
We found and corrected an issue with using the Clear button, so depending on your setup you may run into that. The fix will be included in the next maintenance release. As an alternative to the Clear button, you can set DateTimeEditBox.CheckBoxVisibility="Visible". Unchecking the checkbox has the same effect as the clear button.


Actipro Software Support

Posted 10 years ago by Azhagiri Selvam
Avatar
Thanks for the reply. We are currently using the version 10.1.522.0. Can you please let me know if this issue is fixed in this particular version. If it isn't the current version, point me to the current version number.
Posted 10 years ago by Azhagiri Selvam
Avatar
Today button looks more like a text. I feel it can be modified to look like a hyperlink similar to Clear hyperlink. And also clicking on "Today" just sets the focus on the current date but doesn't select it. Is this the intended behavior?

[Modified at 05/24/2010 04:56 AM]
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Giri,

The fix to the issue we mentioned has not been released yet. It will be included in the next maintenance release, which would be 10.1.523.0.

You can certainly change the today button to use a Hyperlink. It is represented by a CalendarTodayButton control, so you can create an implicit style for that type that uses a custom control template. You would just need to have the hyperlink/button use the ActiproSoftware.Windows.Controls.Editors.Primitives.Calendar.CalendarCommands.GoToToday command or the SelectToday command. The latter command would also change the selection when you click the today button.


Actipro Software Support

Posted 10 years ago by Azhagiri Selvam
Avatar
I have defined a style template similar to the following. But I am not sure about to which property in my DateTimeEditBox this style should be applied. I couldn't get hold of CalendarTodayButton. I feel DateTimeEditBox isn't developer friendly :-(

<Style x:Key="MyMonthCalendarTodayStyle" TargetType="{x:Type calendar:CalendarTodayButton}">
<Setter Property="ContentTemplate" Value="{DynamicResource TodayButtonStyle}" />
</Style>

<ControlTemplate x:Key="TodayButtonStyle" TargetType="{x:Type calendar:CalendarTodayButton}">
<TextBlock>
<Hyperlink>
<TextBlock Text="{StaticResource Text}"/>
</Hyperlink>
</TextBlock>
</ControlTemplate>

Inputs on this will be really helpful. Thanks in advance.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Giri,

I looked at your sample code and there are a number of issues with it. Namely they are:

1. You need to use an implicit Style for CalendarTodayButton, which means it doesn't have an x:Key defined.
2. You are setting a ControlTemplate to the ContentTemplate property, whose type is DataTemplate. You should use the Template property.
3. You should probably move the ControlTemplate above the Style, and reference it using StaticResource. I'm not sure it would work the way you have it ordered.
4. Your ControlTemplate has a TextBlock in a Hyperlink in another TextBlock. The inner most TextBlock should be a Run.
5. The TextBlock of the inner most TextBlock is set to a resource that you didn't include, so that may not be correct.

Since it looks like you may be new to WPF's styles/template design, you may want to look at some of the articles listed here: http://www.wpfpedia.com/item/details/866/implicit-styles-templates-controls-and-framew


Actipro Software Support

Posted 10 years ago by Azhagiri Selvam
Avatar
Thanks. I will take care of that. But my doubt is, to which property in DateTimeEditBox I should assign this Style.

For e.g. I have used/assigned the following Style to DateTimeEditBox's MonthCalendarStyle property.

<Style x:Key="MyMonthCalendarStyle" TargetType="editors:MonthCalendar">
<Setter Property="IsClearButtonVisible" Value="True" />
<Setter Property="IsTodayButtonVisible" Value="True" />
</Style>

Similarly, to which property in DateTimeEditBox I should apply this new Style(for customizing Today button).
Posted 10 years ago by Azhagiri Selvam
Avatar
We will be using DateTimeEditBox in many screens. In some screens, I want Today button as hyperlink and in others I want it to appear as normal text. Using Implicit Style will customize Today button in all instances of DateTimeEditBox. Correct me if I am wrong.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There isn't a property you can set, you have to use an implicit Style. Where it's applied depends on where the implicit Style is defined. If you put it in the App.Resources then it would be applied to all instances of CalendarTodayButton, assuming there isn't another implicit Style defined further down the visual tree.

You can define the implicit Style per window, or at any level in the visual tree, by including in the appropriate resources. Alternatively, you can define a Style for the DateTimeEditBox that includes the implicit Style. Then you can set specific instances of DateTimeEditBox to use the CalendarTodayButton implicit Style. Something like:
<Style x:Key="DateTimeEditBoxStyle" TargetType="editors:DateTimeEditBox">
    <Style.Resources>
        <Style TargetType="editors:CalendarTodayButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <TextBlock Text="Here" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Style.Resources>
</Style>


Actipro Software Support

Posted 9 years ago by Azhagiri Selvam
Avatar
Thanks for the reply. I declared a Style similar to following and applied it on my datetimeeditbox instances(wherever required). Hope this helps someone.

  <Style x:Key="CalendarWithTodayClearButtonStyle" TargetType="{x:Type editors:DateTimeEditBox}">
    <Style.Resources>
      <Style TargetType="editors:CalendarTodayButton">
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate>
              <Button Content="Today"/>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Style.Resources>
    <Setter Property="MonthCalendarStyle">
      <Setter.Value>
        <Style TargetType="editors:MonthCalendar">
          <Setter Property="IsClearButtonVisible" Value="True"/>
          <Setter Property="ClearButtonContentTemplate">
            <Setter.Value>
              <DataTemplate>
                <Button Content="Clear"/>
              </DataTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </Setter.Value>
    </Setter>
  </Style>
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.