XAML - The property 'Content' is set more than once

后端 未结 3 2135
南方客
南方客 2021-02-06 21:19

Very new to WPF and XAML. I can\'t get my head around why I can\'t place a WPF control where I would like in the following code. My issue is where the

相关标签:
3条回答
  • 2021-02-06 22:05

    By adding your text description to your TabItem you added Content then when you added the Canvas you added an additional item of Content which is not allowed for the TabItem. You need to use a Control that can hold a collection of Children such as Canvas, Grid, StackPanel etc. Try something like this.

    <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>
    
    0 讨论(0)
  • 2021-02-06 22:06

    Certain containers only allow 1 element, other containers allow >1 element. When you get the error message 'Content' is set more than once, it means you have tried to put more than one type of element in a container that only allows 1 element.

    Maybe try this (not tested):

    <TabItem Header="Document Flow" >
    <StackPanel>
    <TextBlock>This is where the outline of the entire document will be placed. </TextBlock>
    <Canvas></Canvas>
    </StackPanel>
    </TabItem>
    
    0 讨论(0)
  • 2021-02-06 22:13

    Try to wrap a content of TabItem in a Grid and use TextBlock to show text:

    <TabItem Header="Document Flow" >
        <Grid>
            <TextBlock Text="This is where the outline of the entire document will be placed."/>
            <Canvas></Canvas>
        </Grid>
    </TabItem>
    
    0 讨论(0)
提交回复
热议问题