C# Edrawing API–的内容;“内容控制”;必须是单个元素
我是WPF的新手。我想连接到Edrawings。我使用了以下说明: 我已经在windowsforms中完成了实现,效果非常好。在Wpf中,我得到以下错误: “ContentControl”的内容必须是单个项 我在这里找到了一些解决方案。但不幸的是,没有什么能解决我的问题 此外,以下是代码(与类似代码相同): 下面是xaml代码:C# Edrawing API–的内容;“内容控制”;必须是单个元素,c#,wpf,api,C#,Wpf,Api,我是WPF的新手。我想连接到Edrawings。我使用了以下说明: 我已经在windowsforms中完成了实现,效果非常好。在Wpf中,我得到以下错误: “ContentControl”的内容必须是单个项 我在这里找到了一些解决方案。但不幸的是,没有什么能解决我的问题 此外,以下是代码(与类似代码相同): 下面是xaml代码: <Window x:Class="PDM.Edrawing" xmlns="http://schemas.microsof
<Window x:Class="PDM.Edrawing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myControls="clr-namespace:PDM"
mc:Ignorable="d"
Title="Edrawing" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<myControls:eDrawingsHostControl Grid.Row="0" FilePath="{Binding Path=Text, ElementName=txtFilePath, UpdateSourceTrigger=Explicit}"/>
<TextBox Grid.Row="1" x:Name="txtFilePath"/>
</Grid>
非常感谢您的帮助:)您必须替换
此.AddChild(主机)代码>与this.Content=host代码>。请注意,这样的方式主机将是唯一的内容。
如果你想在UserControl
中有一些额外的控件,你必须用这些控件定义ControlTemplate
,例如ContentPresenter
。非常有效!非常感谢你能提供更多关于错误的细节吗?这是运行时错误还是编译错误?如果这是一个编译错误,你能告诉我们它抛出错误的确切代码行吗?如果是运行时错误,我会考虑包括一个StActTrand,这样我们就可以得到更多的细节。
<Window x:Class="PDM.Edrawing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:myControls="clr-namespace:PDM"
mc:Ignorable="d"
Title="Edrawing" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<myControls:eDrawingsHostControl Grid.Row="0" FilePath="{Binding Path=Text, ElementName=txtFilePath, UpdateSourceTrigger=Explicit}"/>
<TextBox Grid.Row="1" x:Name="txtFilePath"/>
</Grid>