![](/img/trans.png)
[英]How to fix “The property Content is set more than once” error in XAML when overriding the ContentProperty of ContentPage
[英]XAML - LayoutPanel The property 'Content' is set more than once
我正在尝试在布局面板中添加两个ComboBox,如下面的代码所示。
但是我遇到了一个错误-“属性'Content'设置了多次”。 如何在布局内添加两个组合框?
<!--User Control Layout-->
<dxdo:LayoutGroup x:Name="LayoutGroupTopLevel">
<dxdo:LayoutGroup x:Name="GridViews" ItemWidth="1*" Orientation="Vertical" AllowClose="True" AllowDock="True" AllowFloat="True" AllowHide="True">
<dxdo:LayoutPanel x:Name="Layers" Caption="User Control" ItemHeight="1*">
<dxdo:LayoutGroup>
<dxlc:LayoutItem Label="Plan Type">
<dxe:ComboBoxEdit Height="25" VerticalAlignment="Top" Width="200" Name="BoxEdit">
<dxe:ComboBoxEditItem Content="3 month"/>
<dxe:ComboBoxEditItem Content="2 year"/>
</dxe:ComboBoxEdit>
</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Site">
<dxe:ComboBoxEdit Height="25" VerticalAlignment="Top" Width="200" Name="BoxEdit1"/>
</dxlc:LayoutItem>
</dxdo:LayoutGroup>
</dxdo:LayoutPanel>
<dxdo:LayoutPanel x:Name="LayoutPanel" Caption="Properties" ItemHeight="1*">
<dxlc:LayoutItem Label="Site">
<dxe:ComboBoxEdit Height="25" VerticalAlignment="Stretch" Width="200" Name="ComboBoxEdit"/>
<dxe:ComboBoxEdit Height="25" VerticalAlignment="Stretch" Width="200" Name="ComboBoxEdit1"/>
</dxlc:LayoutItem>
</dxdo:LayoutPanel>
</dxdo:LayoutGroup>
谁能指出我犯的错误?
假设您使用的是DevExpress WPF控件套件,则您的错误是尝试将两个LayoutItem
添加到LayoutPanel
。 它仅支持单个UIElement
或LayoutGroup
作为内容(请参见LayoutPanel文档的 “内容”部分)。 因此,要完成您的目标,您应该使用LayoutGroup
包装项目:
<dxdo:LayoutPanel x:Name="Layers" (...)>
<dxdo:LayoutGroup>
<dxlc:LayoutItem Label="Plan Type">(...)</dxlc:LayoutItem>
<dxlc:LayoutItem Label="Site">(...)</dxlc:LayoutItem>
</dxdo:LayoutGroup>
</dxdo:LayoutPanel>
UPDATE
正如您所指出的(这引起了我的注意),您不能直接将dxlc:LayoutItem
添加到dxdo:LayoutGroup
; 您应该将其包装在dxdo:LayoutControlItem
(同样,全部在文档中):
<dxdo:LayoutPanel x:Name="Layers" (...)>
<dxdo:LayoutGroup>
<dxdo:LayoutControlItem>
<dxlc:LayoutItem Label="Plan Type">(...)</dxlc:LayoutItem>
</dxdo:LayoutControlItem>
<dxdo:LayoutControlItem>
<dxlc:LayoutItem Label="Site">(...)</dxlc:LayoutItem>
</dxdo:LayoutControlItem>
</dxdo:LayoutGroup>
</dxdo:LayoutPanel>
或者,您可以完全删除dxlc:LayoutItem
并仅使用dxdo:LayoutControlItem
(使用Caption
属性代替Label
):
<dxdo:LayoutPanel x:Name="Layers" (...)>
<dxdo:LayoutGroup>
<dxdo:LayoutControlItem Caption="Plan Type">(...)</dxdo:LayoutControlItem>
<dxdo:LayoutControlItem Caption="Site">(...)</dxdo:LayoutControlItem>
</dxdo:LayoutGroup>
</dxdo:LayoutPanel>
澄清
消除歧义:
xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.