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>
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.
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.
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.
The Panel ClassDerived Panel elements are used to position and arrange elements in Extensible Application Markup Language (XAML) and code.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With