This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi I have a data entry window where I have several DropDownDatePicker. My problem is that I do not want a date to appear if the use has not entered a date. Is it possible not to display a default date? Thanks |
|
|
Unfortunately we do not have this feature at the moment (because we do not have the concept of an "undefined" date). Sorry. |
|
|
Hi Ivan, Would you happen to have any try of work around. Thanks
|
|
|
I don't have anything that I have tested or can provide as a sample, but the way I would tackle this would be something like this: 1. Create a user control or custom control with a Date property of type Nullable<DateTime> (or however you want to model the "undefined" date). 2. In the template, create two "views" and overlay them (e.g. create a 1-cell Grid and put both of them in the same cell): 2a. The first is a normal DropDownDateTimePicker. 2b. The second is a custom UI for "no date selected." For simplicity, let's say this is a button that says "Select date," though you could design something nicer, e.g. a label+button combination that looked like an empty DropDownDateTimePicker. Set the Visibility of this view to Collapsed. 3. Use triggers to specify that if the Date is null, the first view's Visibility is Collapsed and the second view's Visibility is Visible. 4. Hook up an event handler or command so that when the user clicks on the "select date" button, it sets the Date property to a suitable default (causing the control to switch to the first view), and opens the drop-down. You may want to consider whether the first view should also have a "delete date" button to reset the Date property to null. Hope this helps -- let us know if you need any help with this or run into any problems. |
|
|
Thanks Ivan, I will give this a try.
|
|
|
FWIW, Ivan's approach works nicely and is pretty simple. Here's the basics of the datatemplate:
< DataTemplate x:Key="DateTimeEditor"> <Grid> <Button Visibility="Collapsed" Content="Select date..." Name="btnSelectDate" Click="btnSelectDate_Click" ></Button> <Grid Name="gridSelectDate" Visibility="Visible" HorizontalAlignment="Stretch" Background="Blue"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <mse:DropDownDatePicker Grid.Column="0"Format="Custom" CustomFormat="{Binding Path=CustomDateFormatString, ElementName=ctlPropertyEditor, Mode=Default}" Value="{Binding DateTimeValue, Mode=TwoWay}" /> <Button Grid.Column="1" Content="Clear" Name="btnClear" IsEnabled="{Binding IsEnabled}" Click="btnClear_Click" ></Button> </Grid> </Grid> <DataTemplate.Triggers> <DataTrigger Value="True" Binding="{Binding DateTimeValue, Converter={StaticResource IsDateTimeNullConverter}}"> <Setter TargetName="btnSelectDate" Property="Visibility" Value="Visible"/> <Setter TargetName="gridSelectDate" Property="Visibility" Value="Collapsed" /> </DataTrigger> <DataTrigger Value="False" Binding="{Binding DateTimeValue, Converter={StaticResource IsDateTimeNullConverter}}"> <Setter TargetName="btnSelectDate" Property="Visibility" Value="Collapsed"/> <Setter TargetName="gridSelectDate" Property="Visibility" Value="Visible" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate>Here is the converter that I used (in my app 1/1/1800 is a null date): Public Class IsDateTimeNullConverter Implements IValueConverterPublic Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert TryDim datVal = DirectCast(value, DateTime) If datVal.Year = 1800 Then Return True Else Return False End IfCatch ex As Exception Return True End Try End FunctionPublic Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack End FunctionEnd ClassAnd here are the event handlers for my buttons: Private Sub btnSelectDate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim dtObject = TryCast(DirectCast(sender, Button).DataContext, DateTimePropertyObject) If Not dtObject Is Nothing ThendtObject.DateTimeValue = Now End If End SubPrivate Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim dtObject = TryCast(DirectCast(sender, Button).DataContext, DateTimePropertyObject) If Not dtObject Is Nothing ThendtObject.DateTimeValue = New DateTime(1800, 1, 1) End If End SubHope this is helpful!
Sean |
|