Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,676 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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;
}
Try this modification:
static readonly DependencyProperty CheckBoxIsCheckedProperty =
DependencyProperty.Register( "CheckBoxIsChecked", typeof( bool? ), typeof( FileControl ), new PropertyMetadata( null, onCheckBoxChanged ) );