Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the property content is set more than once

Tags:

I am getting the following error with my code shown below.

Error:

The property 'Content' is set more than once

Code:

<controls:PanoramaItem Header="headlines">     <TextBlock Text="{Binding Tones}" />     <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">         <ListBox.ItemTemplate>             <DataTemplate>                 <StackPanel Orientation="Horizontal" Margin="0,0,0,17">                     <Image Source="{Binding ImageUrl}" Height="75" Width="100"                         Margin="12,10,9,0" VerticalAlignment="Top"/>                     <StackPanel Width="311">                         <TextBlock Text="{Binding Title}" TextWrapping="Wrap"                             Style="{StaticResource PhoneTextLargeStyle}" />                     </StackPanel>                 </StackPanel>             </DataTemplate>         </ListBox.ItemTemplate>     </ListBox>                 </controls:PanoramaItem> 
like image 280
John Smith Avatar asked Dec 26 '11 22:12

John Smith


People also ask

What is the type of content property in WPF?

Because the Content property is of type Object, there are no restrictions on what you can put in a ContentControl. The Content is displayed by a ContentPresenter, which is in the ControlTemplate of the ContentControl. Every ContentControl type in WPF has a ContentPresenter in its default ControlTemplate.

What is a StackPanel WPF?

A StackPanel allows you to stack elements in a specified direction. By using properties that are defined on StackPanel, content can flow both vertically, which is the default setting, or horizontally.

What is WPF canvas?

Canvas panel is the basic layout Panel in which the child elements can be positioned explicitly using coordinates that are relative to the Canvas any side such as left, right, top and bottom.


1 Answers

A PanoramaItem can only have one child control but you currently have a TextBlock and a ListBox. To fix this, simply add another parent control to hold the TextBlock and ListBox (such as a StackPanel or a Grid). For example:

<controls:PanoramaItem Header="headlines">    <grid>         <TextBlock Text="{Binding Tones}" />         <!--Double line list with image placeholder and text wrapping-->         <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Tones}">             <ListBox.ItemTemplate>                  <DataTemplate>                      <StackPanel Orientation="Horizontal" Margin="0,0,0,17">                          <!--Replace rectangle with image-->                          <Image Source="{Binding ImageUrl}" Height="75" Width="100" Margin="12,10,9,0" VerticalAlignment="Top"/>                          <!--<Rectangle Height="100" Width="100" Fill="#FFE5001b" Margin="12,0,9,0"/>-->                          <StackPanel Width="311">                               <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}"/>                               <!--<TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>-->                          </StackPanel>                      </StackPanel>                   </DataTemplate>              </ListBox.ItemTemplate>         </ListBox>                   </grid>  </controls:PanoramaItem> 
like image 94
keyboardP Avatar answered Nov 13 '22 10:11

keyboardP