Posted 15 years ago
by Richard Carlin

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
<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