在我的应用程序中,我需要显示一组完全类似于Windows Phone 8 Photo App的图像,您可以在图像之间左右滑动。
我已尝试过Panorama和Pivot控件,但两个控件的行为都不像WinRTs FlipView。
全景非常合适,但似乎将“Right-Peek”数量硬连线到控制中。 (如果我错了,请纠正我)
Pivot依次显示滑动时的黑度(手指仍然向下),只有当您松开手指时控件才会显示下一个图像。
有什么建议吗?
答案 0 :(得分:3)
这是WP8的自定义FlipView控件,如WINRT FlipView Control ......
步骤1:添加新的Usercontrol并将其命名为" FlipView.xaml"
第2步:在" FlipView.xaml"
中添加以下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="<" Click="Button_Click"/>
<Button BorderThickness="0" Name="rightButton" FontSize="70" Margin="-25" HorizontalAlignment="Right" VerticalAlignment="Center" Content=">" Click="Button_Click_1"/>
</Grid>
步骤3:在&#34; FlipView.cs&#34;
中添加以下代码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 Usercontrol
实施例: 的xmlns:FlipViewControl =&#34; CLR-名称空间:ImageFlip&#34; (注意:根据您的解决方案名称而有所不同)。
步骤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" };
}
希望这会有所帮助。
谢谢
答案 1 :(得分:1)
没有直接相当于Windows Phone中的FlipView。 Panorama和Pivot控件具有非常不同的功能,专为不同目的而设计。
Telerik有一个SlideView控件,与照片应用程序使用的本机控件非常相似 您还可以免费获取Telerik控件作为Nokia Premium Developer Program的一部分。 (值得调查一下你是否没有开发中心订阅。)
答案 2 :(得分:0)
我知道这不是同一个解决方案,但也许你可以调整这个coverflow example here...,这样图像就不会堆叠而是并排?