DateTime picker doesn't support error template

Grids for WPF Forum

Posted 14 years ago by SledgeHammer01
Version: 10.1.0521
Platform: .NET 4.0
Environment: Windows XP (32-bit)
Avatar
Hi,

I am using a date picker in a property grid. I have noticed that if I throw an exception in the setter, the error template is not shown. You can easily see this in your sample (/ProductSamples/PropertyGridSamples/QuickStart/PropertyEditors/).

1) select DateTimePicker (date only)
2) enter "aaa"
3) field becomes null and you pass a null to the property setter

property grid does not show the red rectangle in this case.

As far as my code goes:

the property...

        [Editor(typeof(DatePropertyEditor), typeof(PropertyEditor))]
        public object FieldMinDT
        {
            get
            {
                return FieldMin;
            }

            set
            {
                                if (value == null) throw new Exception("test");
                FieldMin = value;
            }
        }
the DatePropertyEditor class...

    public class DatePropertyEditor : PropertyEditor
    {
        #region Constructors

        public DatePropertyEditor()
        {
        }

        #endregion

        #region Overrides

        public override DataTemplate ValueTemplate
        {
            get;
            set;
        }

        public override object ValueTemplateKey
        {
            get
            {
                return "DatePropertyEditor";
            }
        }

        public override DataTemplateSelector ValueTemplateSelector
        {
            get;
            set;
        }

        #endregion
    }
the DatePropertyEditor template...

    <DataTemplate x:Key="DatePropertyEditor">

        <shared:DateTimePicker Margin="0" IsEditable="True" BorderThickness="0" Value="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay}"
                               ValueConverterParameter="{x:Static shared:DateTimeToStringPattern.ShortDate}" />

    </DataTemplate>
[Modified at 04/23/2010 12:02 PM]

[Modified at 04/23/2010 12:03 PM]

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

For your code, if you add "ValidatesOnExceptions=True" to your binding then you should see the error template. WPF doesn't turn this on by default.

Our sample actually uses a different method of populating the PropertyGrid, which results in two binding statements. Because of this one binding is invalidated, but the one connected to the visual is not invalidated. Therefore, the visual doesn't display the error template. This is described in detail in this post: http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4746


Actipro Software Support

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.