XAML DockPanel:属性内容设置多次

时间:2014-06-16 08:36:15

标签: xaml dockpanel

我有这个XAML代码,它会抛出错误:

该属性'内容'设置不止一次。

这整个代码指出了同样的错误。非常感谢。

编辑:添加了窗口的XAML

<Window x:Class="AddressBook.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AddressBook"
    Loaded="WindowLoaded"
    SizeToContent="WidthAndHeight"
    MinHeight="480" 
    MinWidth="640">
<Window.Resources>
    <ObjectDataProvider x:Key="ContactList"
                        MethodName ="AddressBook.ContactList,AddressBook" />
    <DataTemplate x:Key="ContactNameTemplate" >
        <TextBlock Text=" {Binding Path=Firstname}" />
    </DataTemplate>
</Window.Resources>
<Grid Background="White" Name="DocumentRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <!-- Menu -->
        <RowDefinition Height="Auto"/>
        <!-- Tool Bar -->
        <RowDefinition Height="Auto"/>
        <!-- Content Area -->
        <RowDefinition Height="Auto"/>
        <!-- Status Bar -->
    </Grid.RowDefinitions>
</Grid>
<DockPanel Name="DockPanel_Menu" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0">
                <Menu Background="White">
                    <MenuItem Header="File">
                        <MenuItem Header="New Contact" Click="LaunchNewContactWizard"/>
                        <MenuItem Header="New Group" Click="NotImplementedMsg"/>
                        <Separator />
                    <MenuItem Header="Properties" Click="NotImplementedMSg"/>
                        <MenuItem Header="Delete" Click="NotImplementedMsg"/>
                        <MenuItem Header="Import">
                            <MenuItem Header="Address book (WAB)..."
                          Click="NotImplementedMsg"/>
                            <MenuItem Header="Business card (vCard)..."
                          Click="NotImplementedMsg"/>
                        </MenuItem>
                        <Separator />
                        <MenuItem Header="Exit" InputGestureText="Alt-F4"
                                  Click="ExitApplication">
                            <MenuItem.ToolTip>
                                <ToolTip>
                                    Click here to exit
                                </ToolTip>
                            </MenuItem.ToolTip>
                        </MenuItem>
                    </MenuItem>
                </Menu>
                <Menu Background="White">
                    <MenuItem Header="Edit">
                        <MenuItem Command="ApplicationCommands.Copy"/>
                        <MenuItem Command="ApplicationCommands.Paste"/>
                    </MenuItem>
                </Menu>
</DockPanel>
</Window>

过去3天我无法对其进行调试:(

1 个答案:

答案 0 :(得分:0)

您必须以下列方式修改代码:

<Window>
...
    <StackPanel>
        <Grid Background="White" Name="DocumentRoot">
        ...
        </Grid>
        <DockPanel Name="DockPanel_Menu" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0">
        ...
        </DockPanel>
    </StackPanel>
</Window>

Window 只能有一个孩子,所以你必须在某个容器中嵌入 Grid DockPanel ,例如 StackPanel ,另一个 DockPanel 等。