2014-11-04 45 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>