question

catendless-6632 avatar image
0 Votes"
catendless-6632 asked Viorel-1 answered

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

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




dotnet-csharpwindows-wpfdotnet-wpf-xaml
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Try this modification:

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.