2013-07-15 35 views
2

在我的應用程序中,我需要顯示一組完全像Windows Phone 8照片應用程序中的圖像集合,您可以在圖像之間左右滑動。WinRT FlipView喜歡WP8中的控件

我試過全景和樞軸控制,但兩個控件不像WinRT FlipView行爲。

全景很適合,但似乎有「右看」金額硬連線到控制。 (請糾正我,如果我錯了)

樞軸反過來顯示刷卡期間的黑度(手指仍然下降),只有當你鬆開手指時顯示下一個圖像,控制器將下一個項目滾動到位。

有什麼建議嗎?

回答

1

在Windows Phone中沒有與FlipView直接等價的功能。 Panorama和Pivot控件具有非常不同的功能,並且設計用於不同的目的。

Telerik有一個SlideView控件,它與照片應用程序使用的本地控件非常相似。
您還可以免費獲得Telerik控件作爲Nokia Premium Developer Program的一部分。 (值得調查,如果你沒有開發中心的訂閱。)

+0

簽出了RadSlideView。完美匹配我的用例。對於99美元而言,這是一筆相對於自己寫的東西 - 如果它當然穩定的話。 –

+0

@OliverWeichhold在過去的項目中使用它已經非常好了。 –

3

這裏是喜歡WinRT的FlipView控制WP8定製FlipView控制...

第1步:添加新的用戶控件,並將它命名爲 「FlipView.xaml」

第2步:添加以下XAML中「FlipView.xaml」

<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}"> 
    <ContentPresenter Name="contentPresenter"/> 
    <Button BorderThickness="0" Name="leftButton" FontSize="70" Margin="-25" HorizontalAlignment="Left" VerticalAlignment="Center" Content="&lt;" Click="Button_Click"/> 
    <Button BorderThickness="0" Name="rightButton" FontSize="70" Margin="-25" HorizontalAlignment="Right" VerticalAlignment="Center" Content="&gt;" Click="Button_Click_1"/> 
</Grid> 

步驟3:添加以下代碼中的 「FlipView.cs」

public partial class FlipView : UserControl 
{ 
    public FlipView() 
    { 
     InitializeComponent(); 
     Datasource = new List<object>(); 
     SelectedIndex = 0; 
    } 

    private IList Datasource; 
    public static readonly DependencyProperty ItemTemplateProperty = 
     DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(FlipView), new PropertyMetadata(default(DataTemplate))); 

    public DataTemplate ItemTemplate 
    { 
     get { return (DataTemplate)GetValue(ItemTemplateProperty); } 
     set 
     { 
      SetValue(ItemTemplateProperty, value); 
      contentPresenter.ContentTemplate = value; 
      contentPresenter.Content = SelectedItem; 
     } 
    } 

    public static readonly DependencyProperty ItemsSourceProperty = 
     DependencyProperty.Register("ItemsSource", typeof(IList), typeof(FlipView), new PropertyMetadata(default(IList))); 

    public IList ItemsSource 
    { 
     get { return (IList)GetValue(ItemsSourceProperty); } 
     set 
     { 
      SetValue(ItemsSourceProperty, value); 
      Datasource = value; 
      SelectedIndex = SelectedIndex; 
     } 
    } 

    public static readonly DependencyProperty SelectedIndexProperty = 
     DependencyProperty.Register("SelectedIndex", typeof(int), typeof(FlipView), new PropertyMetadata(default(int))); 

    public int SelectedIndex 
    { 
     get { return (int)GetValue(SelectedIndexProperty); } 
     set 
     { 
      SetValue(SelectedIndexProperty, value); 

      rightButton.Visibility = leftButton.Visibility = Visibility.Visible; 
      if (SelectedIndex == 0) 
      { 
       leftButton.Visibility = Visibility.Collapsed; 
      } 

      if (SelectedIndex + 1 == Datasource.Count) 
      { 
       rightButton.Visibility = Visibility.Collapsed; 
       SelectedItem = Datasource[SelectedIndex]; 
      } 

      if (Datasource.Count > SelectedIndex + 1) 
      { 
       SelectedItem = Datasource[SelectedIndex]; 
      } 
     } 
    } 

    public static readonly DependencyProperty SelectedItemProperty = 
     DependencyProperty.Register("SelectedItem", typeof(object), typeof(FlipView), new PropertyMetadata(default(object))); 

    public object SelectedItem 
    { 
     get { return (object)GetValue(SelectedItemProperty); } 
     set 
     { 
      SetValue(SelectedItemProperty, value); 
      contentPresenter.Content = SelectedItem; 
     } 
    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     SelectedIndex--; 
    } 

    private void Button_Click_1(object sender, RoutedEventArgs e) 
    { 
     SelectedIndex++; 
    } 
} 

步驟4:現在在炫魅,添加命名空間來使用flipview用戶控件

實施例: 的xmlns:FlipViewControl = 「CLR-名稱空間:ImageFlip」(注:根據你的解決方案名稱不同)。

第5步:使用命名空間,添加flipview控制,遵循..

<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <FlipViewControl:FlipView Name="imgViewer"> 
     <FlipViewControl:FlipView.ItemTemplate> 
      <DataTemplate> 
       <Image Source="{Binding}" Stretch="Fill"/> 
      </DataTemplate> 
     </FlipViewControl:FlipView.ItemTemplate> 
    </FlipViewControl:FlipView> 
</Grid> 

第6步:添加以下代碼mainpage.cs

// Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 

     // Sample code to localize the ApplicationBar 
     //BuildLocalizedApplicationBar(); 
     imgViewer.ItemsSource = new List<string> { "/Images/1.jpg", "/Images/2.jpg", "/Images/3.jpg" }; 
    } 

希望這會有所幫助。

謝謝