Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wpf

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> 

like image 858
bernieslearnings Avatar asked Feb 14 '13 06:02

bernieslearnings


People also ask

What is stack panel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

What is XAML in C#?

C# interfaces - Blazor, API, UWP, WPF, Office XAML stands for Extensible Application Markup Language. It's a simple and declarative language based on XML. In XAML, it very easy to create, initialize, and set properties of objects with hierarchical relations.

What is XAML in Visual Studio?

The XAML Designer in Visual Studio and Blend for Visual Studio provides a visual interface to help you design XAML-based apps, such as WPF and UWP.

Which panel in WPF is well suited to place elements in an ordered and aligned manner?

The Panel ClassDerived Panel elements are used to position and arrange elements in Extensible Application Markup Language (XAML) and code.


2 Answers

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> 
like image 57
Mark Hall Avatar answered Sep 23 '22 20:09

Mark Hall


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> 
like image 27
failedprogramming Avatar answered Sep 23 '22 20:09

failedprogramming