Windows Phone FlipView System.ArgumentException

时间:2014-11-04 20:16:47

标签: c# windows-phone-8.1 flipview

我在WindowsPhone应用中使用FlipView时遇到问题。 我有一个带有FlipView的页面,它有ItemsSource绑定到ItemsGroup和SelectedItem绑定到CurrentItem。 FlipView的DataTemplate包含附加了属性Html的WebView,该属性Html绑定到CurrentItem的Html。一切顺利,但应用程序不时与System.ArgumentException崩溃,我不知道什么是错的。

XAML:

<Page
x:Class="UkraineNews.ItemPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:common="using:News.Common"
xmlns:viewModel="using:News.ViewModel"
xmlns:converter="using:News.Converter">
<Page.DataContext>
    <viewModel:PhoneGroupViewModel/>
</Page.DataContext>
<Page.Resources>
    <converter:DateConverter x:Key="DateConverter" 
                             IsShowFullDate="True"/>
</Page.Resources>
<Grid>
    <FlipView ItemsSource="{Binding Group.Items}"
              SelectedItem="{Binding Group.CurrentItem, Mode=TwoWay}">
        <FlipView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Border Grid.Row="0" 
                            Background="{StaticResource ItemBorderBackground}"
                            HorizontalAlignment="Right"
                            Padding="5"
                            CornerRadius="0,0,0,5">
                        <TextBlock Text="{Binding Published, Converter={StaticResource DateConverter}}"/>
                    </Border>
                    <TextBlock Grid.Row="1"
                               TextWrapping="Wrap"
                               Text="{Binding Title}"
                               FontWeight="Bold"
                               Margin="24,0"
                               FontSize="20"
                               Foreground="{StaticResource LeftMenuBackgroundBrush}"/>
                    <WebView Grid.Row="2" 
                             NavigationStarting="WebView_NavigationStarting"
                             common:WebViewBehaviour.Html="{Binding Html}"/>
                </Grid>
            </DataTemplate>
        </FlipView.ItemTemplate>
    </FlipView>
</Grid>

C#:

  public class NewsItem 
  {
     public string Title { get; set; }
     public string Link { get; set; }
     public DateTime Published { get; set; }
     public string Html { get; set; }
     public string Image { get; set; }
  }

错误:

  

参数不正确。 System.ArgumentException:值不在预期范围内。

1 个答案:

答案 0 :(得分:2)

我用我的自定义替换了FlipView的默认Templete,其中我删除了2.5点边框边距。我不知道怎么做,但它确实有效。也许它与进入边缘区域的指针有关,因为从边缘滑动时发生了错误。

<Style x:Key="FlipViewStyle" TargetType="FlipView">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="TabNavigation" Value="Once"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/>
    <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False"/>
    <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False"/>
    <Setter Property="ScrollViewer.IsHorizontalScrollChainingEnabled" Value="True"/>
    <Setter Property="ScrollViewer.IsVerticalScrollChainingEnabled" Value="True"/>
    <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
    <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True"/>
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel AreScrollSnapPointsRegular="True" 
                                        Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="FlipView">
                <Grid>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Background="{TemplateBinding Background}">
                        <Grid>
                            <ScrollViewer x:Name="ScrollingHost" 
                                          AutomationProperties.AccessibilityView="Raw" 
                                          BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" 
                                          HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" 
                                          HorizontalSnapPointsType="MandatorySingle"
                                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" 
                                          IsTabStop="False" 
                                          IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" 
                                          IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}" 
                                          IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}" 
                                          IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" 
                                          IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" 
                                          Padding="{TemplateBinding Padding}" 
                                          TabNavigation="{TemplateBinding TabNavigation}" 
                                          VerticalSnapPointsType="MandatorySingle" 
                                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" 
                                          VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" 
                                          ZoomMode="Disabled">
                                <ItemsPresenter/>
                            </ScrollViewer>
                        </Grid>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>