2016-04-27 163 views
1

我想在Layout面板中添加两个ComboBoxes,如下面的代码所示。XAML - LayoutPanel属性'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> 

任何人都可以指出我犯的错误吗?

回答

2

假设您使用的是DevExpress WPF控件套件,您的错误是试图将两个LayoutItem s添加到LayoutPanel。它仅支持单个UIElementLayoutGroup作为内容(请参阅LayoutPanel documentation,“内容”一节)。因此,要完成你的目标,你应该换的项目有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:LayoutItemdxdo: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"
+0

为u建议我改变了代码和我已经编辑它上面为好。但我仍然得到这个错误 - “一个'LayoutItem'类型的值不能被添加到'BaseLayoutItemCollection'类型的集合或字典中。 – Dazzler

+0

是的,我正在使用DevExpress WPF控件套件。 – Dazzler

+0

非常感谢,像一个魅力:) – Dazzler