设计器进程在具有绑定内容的自定义控件中终止
Designer process terminated in Custom Control with Binding Content
我已经从 Gruopbox 创建了自定义用户控件。但是,为了用作视图中的容器,我必须为 Content
创建一个 DependecyProperty
。这会导致 VS2017 中出现 Unhandled Exception has occurred
错误。
但是,只有当我将 groupbox 中的 Content
属性绑定到我的新 属性 时才会发生这种情况。
<UserControl
x:Class="Infrastructure.Controls.GroupBox.CollectionBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="Form"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<GroupBox Content="{Binding Content, ElementName=Form}"/>
</UserControl>
后面有代码
public new object Content
{
get => (object)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public new static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(object), typeof(CollectionBox), new PropertyMetadata(null));
我尝试在与其他控件的绑定中使用 FalloutValue
,因为我假设设计者不知道在容器中放入什么。然而,错误不断发生。
在运行时和视图设计器中,控件看起来和工作正常。只是在它的设计器中我看不到它。
谢谢。
您不需要另一个 Content 属性,只需要另一个 ControlTemplate,它定义控件的视觉结构,包括绑定到控件 Content
:
的 GroupBox
<UserControl x:Class="Infrastructure.Controls.GroupBox.CollectionBox" ...>
<UserControl.Template>
<ControlTemplate TargetType="UserControl">
<Border> <!-- or any other control(s) here -->
<GroupBox Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</UserControl.Template>
</UserControl>
我已经从 Gruopbox 创建了自定义用户控件。但是,为了用作视图中的容器,我必须为 Content
创建一个 DependecyProperty
。这会导致 VS2017 中出现 Unhandled Exception has occurred
错误。
但是,只有当我将 groupbox 中的 Content
属性绑定到我的新 属性 时才会发生这种情况。
<UserControl
x:Class="Infrastructure.Controls.GroupBox.CollectionBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="Form"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<GroupBox Content="{Binding Content, ElementName=Form}"/>
</UserControl>
后面有代码
public new object Content
{
get => (object)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public new static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(object), typeof(CollectionBox), new PropertyMetadata(null));
我尝试在与其他控件的绑定中使用 FalloutValue
,因为我假设设计者不知道在容器中放入什么。然而,错误不断发生。
在运行时和视图设计器中,控件看起来和工作正常。只是在它的设计器中我看不到它。
谢谢。
您不需要另一个 Content 属性,只需要另一个 ControlTemplate,它定义控件的视觉结构,包括绑定到控件 Content
:
<UserControl x:Class="Infrastructure.Controls.GroupBox.CollectionBox" ...>
<UserControl.Template>
<ControlTemplate TargetType="UserControl">
<Border> <!-- or any other control(s) here -->
<GroupBox Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</UserControl.Template>
</UserControl>