Problem with DateTimeEditor

Grids for WPF Forum

Posted 10 years ago by Richard Carlin
Avatar
I have created a test data structure with a property TimeSpan intialized to 9:30 AM. When I attach a DateTimeEditor (same thing happens with a TimeSpanEditor) to a propertygird using a data template, it never shows the time. Im not sure what I am doing wrong but the code for the editor is below.

<my:PropertyGrid Margin="0" Name="PropertyGrid1">
<my:PropertyGrid.Resources>
<DataTemplate x:Key="TimeTemplate">
<Editors1:DateTimeEditBox Margin="0"
HorizontalAlignment="Stretch"
SpinnerVisibility="Visible"
Format="t"
IsChecked="True"
DropDownButtonVisibility="Collapsed"
InitialValue="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}, Mode=OneTime}"
Value="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}, Mode=TwoWay}">
</Editors1:DateTimeEditBox>
</DataTemplate>
</my:PropertyGrid.Resources>
<my:PropertyGrid.PropertyEditors>
<Editors:PropertyEditor PropertyType="{x:Type System:TimeSpan}" ValueTemplate="{StaticResource TimeTemplate}" />
</my:PropertyGrid.PropertyEditors>
</my:PropertyGrid>

and the C# code

public Window1()
{
InitializeComponent();
var testData = new TestData();
PropertyGrid1.SelectedObject = testData;
}

TestData has one TimeSpan property

Comments (4)

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

For things like this, please put together a small sample project and send it over to our support address.

From the code above, you cannot bind a DateTimeEditBox to a TimeSpan property. The DateTimeEditBox control only supports DateTime values. You would need to use the TimeSpanEditBox control, which sounds like you tried. Also keep in mind that the Format properties are not the same across the various controls, so that may be your issue if you are just changing the control name.


Actipro Software Support

Posted 10 years ago by Richard Carlin
Avatar
Project submitted in a support ticket.
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Richard,

The problem is that you are setting IsChecked to true. This effectively sets the Value property to null, which seems to cause problems with the WPF binding system. We've seen this in one other place, where one property (i.e. IsChecked) sets another property (i.e. Value) internally and is used in a DataTemplate. I believe there is a new mechanism built into .Net 4.0 to handle this type of situation, but we still support .Net 3.0 so we cannot leverage that at this time.

Regardless, you shouldn't need to set IsChecked in your XAML. If you remove that line, then the time span will display correctly.


Actipro Software Support

Posted 10 years ago by Richard Carlin
Avatar
Thanks that worked
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.