Share via

WPF custom control reported an error: the default value type does not match the type of the "ischecked" property.

cat endless 21 Reputation points
2021-09-26T13:37:35.01+00:00

To write a WPF custom control, add a checkbox in it, and then register a dependency to expose it to the outside world so as to obtain the ischecked status. Now an error is reported:
Error xdg0062 default value type does not match the type of 'ischecked' property

 public Nullable<Boolean> CheckBoxIsChecked
         {
             get { return (Nullable<Boolean>)GetValue(CheckBoxIsCheckedProperty); }
             set { SetValue(CheckBoxIsCheckedProperty, value); }
         }
         // Using a DependencyProperty as the backing store for ChcckBoxIsChecked.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty CheckBoxIsCheckedProperty =
             DependencyProperty.Register("IsChecked", typeof(Nullable<Boolean>), typeof(FileControl), new PropertyMetadata("CheckBox",new PropertyChangedCallback(onCheckBoxChanged)));
         static void onCheckBoxChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
         {
             ((FileControl)sender).OnCheckBoxValueChanged(args);
         }
         private void OnCheckBoxValueChanged(DependencyPropertyChangedEventArgs e)
         {
             bool temp = bool.Parse(e.NewValue.ToString());
             this.checkBox.IsChecked = (Nullable < Boolean >) temp;
         }
Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
Developer technologies | XAML

A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 126.7K Reputation points
    2021-09-26T14:15:02.65+00:00

    Try this modification:

    static readonly DependencyProperty CheckBoxIsCheckedProperty =
       DependencyProperty.Register( "CheckBoxIsChecked", typeof( bool? ), typeof( FileControl ), new PropertyMetadata( null, onCheckBoxChanged  ) );
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.