【问题标题】:WP8 Phone Pivot -- Items collection must be empty before using ItemsSourceWP8 Phone Pivot -- 在使用 ItemsSource 之前,Items 集合必须为空
【发布时间】:2014-06-03 22:56:27
【问题描述】:
<Grid x:Name="LayoutRoot" Background="Transparent">

    <Grid.Resources>
        <DataTemplate x:Name="GameCardViewTemplate">
            <ScrollViewer VerticalScrollBarVisibility="Hidden">
                <Canvas x:Name="Card" HorizontalAlignment="Left" Height="214" VerticalAlignment="Top" Width="480" Background="#FF760000">
                    <Grid x:Name="CAgeGrid" HorizontalAlignment="Left" Height="84" Margin="0,216,0,0" VerticalAlignment="Top" Width="480" Background="#FF111111" DoubleTap="PlaceBet">
                        <TextBlock x:Name="CAgeL" HorizontalAlignment="Left" Margin="24,36,0,0" TextWrapping="Wrap" Text="Age" VerticalAlignment="Top" FontSize="24"/>
                        <TextBlock x:Name="CAgeV" HorizontalAlignment="Left" Margin="227,36,0,0" TextWrapping="Wrap" Text="{Binding Age}" VerticalAlignment="Top" FontSize="24"/>
                        <TextBlock x:Name="CAgeSep" HorizontalAlignment="Left" Margin="167,40,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" FontSize="18" FontWeight="Bold"/>
                        <Canvas HorizontalAlignment="Left" Height="84" Margin="104,72,0,-72" VerticalAlignment="Top" Width="100"/>
                    </Grid>
                </Canvas>
            </ScrollViewer>
        </DataTemplate>
    </Grid.Resources>


    <!--Pivot Control-->
    <phone:Pivot x:Name="P0Card" Title="Your Turn" ItemsSource="{Binding CardCollection}">

        <!--Host View-->
        <phone:PivotItem ContentTemplate="{StaticResource GameCardViewTemplate}" />

        <!--Computer View-->
        <phone:PivotItem ContentTemplate="{StaticResource GameCardViewTemplate}" />

    </phone:Pivot>
</Grid>

我用的是Visual Studio 2013,好像没有带$

我检查了 "Items collection must be empty before using ItemsSource." 和其他此类来源,但仍然无法解决 - 我不断收到“使用 ItemsSource 之前项目集合必须为空”

【问题讨论】:

    标签: c# windows-phone-8


    【解决方案1】:

    去掉这部分,你只能有一个。

        <!--Host View-->
        <phone:PivotItem ContentTemplate="{StaticResource GameCardViewTemplate}" />
    
        <!--Computer View-->
        <phone:PivotItem ContentTemplate="{StaticResource GameCardViewTemplate}" />
    

    您在 XAML 中有 ItemsSource 或 Items,但不能同时拥有。

    【讨论】:

      【解决方案2】:

      正如@III 所指出的,您不能同时直接添加ItemsSource 设置和PivotItems。

      如果您打算从 XAML 设置 PivotItemsContentTemplate 而不是填充 Pivot,您可以使用样式来做到这一点:

      <phone:Pivot x:Name="P0Card" Title="Your Turn" ItemsSource="{Binding CardCollection}">
          <phone:Pivot.Resources>
              <Style TargetType="phone:PivotItem">
                  <Setter Property="ContentTemplate" Value="{StaticResource GameCardViewTemplate}"/>
              </Style>
          </phone:Pivot.Resources>
      </phone:Pivot>
      

      【讨论】:

      • 谢谢,伙计。只好试试这个了。似乎已经解决了这个问题,但它引入了另一个问题。绑定似乎无法正常工作,屏幕现在只显示 typeof(CardCollection)。稍后将对此进行探索。如果您有任何想法,请发送给他们。谢谢!
      猜你喜欢
      • 2021-07-19
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 2012-07-24
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多