A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
Try moving the InitializeComponent( ) line to the beginning.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I bound the ischecked property of the checkbox before loading the component
public FileControl()
{
RelativeSource relativeSource = new RelativeSource();
relativeSource.Mode = RelativeSourceMode.FindAncestor;
relativeSource.AncestorType = typeof(FileControl);
Binding bind = new Binding() { RelativeSource=relativeSource };
checkBox.SetBinding(FileIsCheckedIsCheckedProperty,bind);
InitializeComponent();
}
Custom dependencies:
public Nullable<bool> FileIsChecked
{
get { return (Nullable<bool>)GetValue(FileIsCheckedIsCheckedProperty); }
set { SetValue(FileIsCheckedIsCheckedProperty, value); }
}
// Using a DependencyProperty as the backing store for ChcckBoxIsChecked. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FileIsCheckedIsCheckedProperty =
DependencyProperty.Register("FileIsChecked", typeof(Nullable<bool>), typeof(FileControl), new FrameworkPropertyMetadata(false));
Then run in MainWindow with an error:
CheckBox.FileIsChecked Nullable`1 Source not found: RelativeSource FindAncestor, AncestorType='FileOperator.FileControl', AncestorLevel='1'。
I have no problem binding XAML in the foreground and can access it normally:
<CheckBox Name="checkBox" IsChecked="{Binding IsChecked, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:FileControl}}}">
</CheckBox>
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
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.
Try moving the InitializeComponent( ) line to the beginning.