51

WPF と XAML の新機能です。次のコードで、WPF コントロールを配置したい場所に配置できない理由がわかりません。私の問題は、<canvas></canvas>タグがどこにあるかです。この場所に置くと、「プロパティ「コンテンツ」が複数回設定されています」というメッセージが表示されます

Content プロパティが設定されている場所を誰かが簡単に説明できれば、それが最も役に立ちます。

次の記事をチェックアウトしましたが、役に立ちませんでした: プロパティ 'Content' が複数回設定され ています プロパティ コンテンツが複数回設定されています プロパティ コンテンツが複数回 設定されてい ます プロパティ 'Content' が複数回設定されています ボタン WPF ControlTemplate の原因エラー「プロパティ 'content' が複数回設定されています」

<Window x:Class="PDFIndexer.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid x:Name="ParentGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="1*" />
        <RowDefinition Height="25" />
    </Grid.RowDefinitions>
    <Menu Grid.Row="0" >
        <MenuItem Header="File" >
            <MenuItem Header="Open Project" Click="MenuItem_Click_1"></MenuItem>
            <MenuItem Header="Save Project"></MenuItem>
            <MenuItem Header="Close Project"></MenuItem>
            <Separator></Separator>
            <MenuItem Header="Exit"></MenuItem>
        </MenuItem>
        <MenuItem Header="Edit"></MenuItem>
    </Menu>
    <TabControl Grid.Row="1">
        <TabItem Header="Document Flow" >
            This is where the outline of the entire document will be placed.
            <Canvas></Canvas>
         </TabItem>
        <TabItem Header="Preview">
            This is where the preview will be drawn to screen.
        </TabItem>
        <TabItem Header="Resources">
            This is where the resources { graphic files, fonts, data files }
        </TabItem>
        <TabItem Header="Code Library">
            This is where the user can save re-usable bits of code. Useful when adding intel barcodes or Address blocks etc...
        </TabItem>
    </TabControl>


    <StatusBar Grid.Row="2">
        Items
    </StatusBar>
</Grid>

4

3 に答える 3

59

追加したコンテンツにテキストの説明を追加することによりTabItem、キャンバスを追加したときに、TabItem. Canvas、Grid、StackPanel などの Children のコレクションを保持できる Control を使用する必要があります。このようなものを試してください。

<TabControl Grid.Row="1">
    <TabItem Header="Document Flow">
        <Canvas>
            <TextBlock>
                This is where the outline of the entire document will be placed.
            </TextBlock>
        </Canvas>
    </TabItem>
    <TabItem Header="Preview">
        This is where the preview will be drawn to screen.
    </TabItem>
    <TabItem Header="Resources">
        This is where the resources { graphic files, fonts, data files }
    </TabItem>
    <TabItem Header="Code Library">
        This is where the user can save re-usable bits of code. Useful when adding intel barcodes or Address blocks etc...
    </TabItem>
</TabControl>
于 2013-02-14T06:28:06.130 に答える
12

特定のコンテナーは 1 つの要素のみを許可し、他のコンテナーは 1 つ以上の要素を許可します。「コンテンツ」が複数回設定されているというエラー メッセージが表示された場合は、1 つの要素しか許可されていないコンテナーに複数の種類の要素を入れようとしたことを意味します。

多分これを試してください(テストされていません):

<TabItem Header="Document Flow" >
<StackPanel>
<TextBlock>This is where the outline of the entire document will be placed. </TextBlock>
<Canvas></Canvas>
</StackPanel>
</TabItem>
于 2013-02-14T06:18:40.907 に答える
4

のコンテンツをラップして、テキストを表示するために使用してみTabItemてくださいGrid:TextBlock

<TabItem Header="Document Flow" >
    <Grid>
        <TextBlock Text="This is where the outline of the entire document will be placed."/>
        <Canvas></Canvas>
    </Grid>
</TabItem>
于 2013-02-14T06:17:47.297 に答える