属性内容设置不止一次

Joh*_*ith 24 xaml windows-phone-7

我的代码如下所示,我收到以下错误.

错误:"属性'内容'设置多次"

码:

        <controls:PanoramaItem Header="headlines">
            <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>                
        </controls:PanoramaItem>
Run Code Online (Sandbox Code Playgroud)

key*_*rdP 38

A PanoramaItem只能拥有一个子控件但你现在有a TextBlock和a ListBox.要解决此问题,只需添加另一个父控件来保存TextBlock和ListBox(例如a StackPanel或a Grid).例如:

<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>
Run Code Online (Sandbox Code Playgroud)

  • 这让我难以忍受了这么久 (4认同)