XAML - The property 'Content' is set more than once
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 <canvas></canvas>
tags are. Anything I put in this place gives me 'The property 'Content' is set more than once'
If anyone could explain in simple terms where the Content property is set that would be most helpful.
I have checked out the following articles to no avail: the property 'Content' is set more than once the property content is set more than once Property content is set more than once The property 'Content' is set more than once Button WPF ControlTemplate causeing error "The property 'content' is set more than once"
<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>
Solution 1:
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>
Solution 2:
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>
Solution 3:
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>