2014-11-04 42 views
1

我在我的WindowsPhone应用程序中使用FlipView有问题。 我有一个页面与FlipView,其中有ItemsSource绑定到ItemsGroup和SelectedItem绑定到CurrentItem。 FlipView的DataTemplate包含WebView,它具有绑定到CurrentItem的Html的属性Html。一切顺利,但应用程序不时崩溃与System.ArgumentException不时,我不知道什么是错的。WindowPhone FlipView 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; } 
    } 

错误:

The parameter is incorrect. System.ArgumentException: Value does not fall within the expected range.

+0

我正在观察同样的行为。我认为当用户与控件交互时添加项目时,这是flipview中的一个错误。不能悲伤地重现或找到错误。 – 2014-12-28 14:44:47

+0

看起来问题是在FlipView的默认模板中有2.5分的边距,但我不知道这与这个问题有什么关系。我已经删除了他们,问题没有了。 – 2014-12-28 16:48:40

+0

您可以扩展您的解决方案吗? – 2014-12-31 09:55:17

回答

2

我把它换成默认Templete为FlipView与我自定义的,其中我删除了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>