【问题标题】:XAML DockPanel: The property content is set more than onceXAML DockPanel:属性内容设置不止一次
【发布时间】:2014-06-16 08:36:14
【问题描述】:

我有这个 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 天我无法真正调试它:(

【问题讨论】:

  • 您粘贴的代码是可编译的。你的问题在别的地方。你能粘贴整个窗口或用户控件的 XAML 吗?

标签: xaml dockpanel


【解决方案1】:

您必须通过以下方式修改您的代码:

<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 只能有一个孩子,因此您必须将 GridDockPanel 嵌入到某个容器中,例如StackPanel,另一个 DockPanel 等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多