C# 在windows 8中自动翻转图片
我有一个翻转视图,我希望它每C# 在windows 8中自动翻转图片,c#,image,C#,Image,我有一个翻转视图,我希望它每n秒自动更改一次图像,而不给用户单击右键或左键的选项。使用a来控制更改图像的时间间隔,并在上设置属性(按名称-如果使用MVVM,则在viewmodel上设置绑定到SelectedIndex的属性) 编辑 下面是一个使用文本块而不是图像的示例(FlipView项目中的内容与执行操作无关) MainPage.xaml MainPage.xaml.cs 使用系统; 使用Windows.UI.Xaml; 使用Windows.UI.Xaml.Controls; 使用Wind
n
秒自动更改一次图像,而不给用户单击右键或左键的选项。使用a来控制更改图像的时间间隔,并在上设置属性(按名称-如果使用MVVM,则在viewmodel上设置绑定到SelectedIndex的属性)
编辑
下面是一个使用文本块而不是图像的示例(FlipView项目中的内容与执行操作无关)
MainPage.xaml
MainPage.xaml.cs
使用系统;
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Navigation;
名称空间App1
{
///
///可以单独使用或在框架内导航到的空页。
///
公共密封部分类主页
{
//找个地方存放计时器
专用只读调度程序计时器;
//放置上次设置显示项目时的存储位置
私有日期时间\u lastChange;
公共主页()
{
初始化组件();
//配置计时器
_计时器=新调度程序
{
//设置滴答声之间的间隔(在本例中为2秒,以查看其工作情况)
间隔=时间间隔从秒(2)
};
//更改计时器计时时显示的内容
_timer.Tick+=ChangeImage;
//启动计时器
_timer.Start();
}
///
///当计时器计时时更改图像
///
///
///
私有void ChangeImage(对象发送方,对象o)
{
//获取翻转视图中的项目数
var totalItems=OfflipView.Items.Count;
//计算新项目的索引(当前索引加上一,如果下一个项目超出范围,则返回零)
var newItemIndex=(TheFlipView.SelectedIndex+1)%totalItems;
//在翻转视图上设置显示项目的索引
TheFlipView.SelectedIndex=newItemIndex;
}
///
///当此页面即将显示在框架中时调用。
///
///描述如何访问此页的事件数据。参数
///属性通常用于配置页面。
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
}
///
///当用户手动更改显示的项目时,请重置计时器,这样我们就不会在最后一个间隔的剩余时间继续前进
///
///
///
私有void DisplayedItemChanged(对象发送者,选择ChangedEventArgs e)
{
//显示时间增量。。。
var currentTime=DateTime.Now;
如果(_lastChange!=默认值(日期时间))
{
TimeDelta.Text=(currentTime-_lastChange).ToString();
}
_lastChange=当前时间;
//由于页面是在计时器启动之前配置的,请检查以确保我们确实有计时器
如果(!ReferenceEquals(_timer,null))
{
_timer.Stop();
_timer.Start();
}
}
}
}
你想翻转什么?应用程序图标
或该应用程序中的任何特定图像??更具体地说,如何询问()否我在翻转视图中添加了3幅图片作为源,要更改图片,用户必须单击左右箭头,我希望3张图片每10/20秒自动更改扫描您请给我一个关于FlipView selectedIndex的示例我创建了计时器,我猜FlipView代码将被放置在计时器功能public void Timer()中{dispatchermer imagesTimer=new dispatchermer();imagesTimer.Interval=new TimeSpan(0,0,0,15);imagesTimer.Tick+=Timer_Tick;}私有无效Timer_Tick(对象发送方,对象e){抛出新的NotImplementedException();}我将在一个小时或更长的时间内准备并发布一个示例so@user1951890这回答了你的问题吗?
<Page
x:Class="App1.MainPage"
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"
mc:Ignorable="d" FontSize="50" FontWeight="Bold">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Stick in a place to show what our interval between changing content is -->
<TextBlock x:Name="TimeDelta" Text="Waiting for first change..."/>
<FlipView x:Name="TheFlipView" SelectionChanged="DisplayedItemChanged" Grid.Row="1">
<!-- Statically add some items -->
<FlipView.Items>
<FlipViewItem>
<TextBlock Text="Item1" />
</FlipViewItem>
<FlipViewItem>
<TextBlock Text="Item2" />
</FlipViewItem>
<FlipViewItem>
<TextBlock Text="Item3" />
</FlipViewItem>
</FlipView.Items>
</FlipView>
</Grid>
</Page>
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace App1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage
{
//Make a place to store the timer
private readonly DispatcherTimer _timer;
//Make a place to store the last time the displayed item was set
private DateTime _lastChange;
public MainPage()
{
InitializeComponent();
//Configure the timer
_timer = new DispatcherTimer
{
//Set the interval between ticks (in this case 2 seconds to see it working)
Interval = TimeSpan.FromSeconds(2)
};
//Change what's displayed when the timer ticks
_timer.Tick += ChangeImage;
//Start the timer
_timer.Start();
}
/// <summary>
/// Changes the image when the timer ticks
/// </summary>
/// <param name="sender"></param>
/// <param name="o"></param>
private void ChangeImage(object sender, object o)
{
//Get the number of items in the flip view
var totalItems = TheFlipView.Items.Count;
//Figure out the new item's index (the current index plus one, if the next item would be out of range, go back to zero)
var newItemIndex = (TheFlipView.SelectedIndex + 1) % totalItems;
//Set the displayed item's index on the flip view
TheFlipView.SelectedIndex = newItemIndex;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
/// <summary>
/// When the user changes the item displayed manually, reset the timer so we don't advance at the remainder of the last interval
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DisplayedItemChanged(object sender, SelectionChangedEventArgs e)
{
//Show the time deltas...
var currentTime = DateTime.Now;
if (_lastChange != default(DateTime))
{
TimeDelta.Text = (currentTime - _lastChange).ToString();
}
_lastChange = currentTime;
//Since the page is configured before the timer is, check to make sure that we've actually got a timer
if (!ReferenceEquals(_timer, null))
{
_timer.Stop();
_timer.Start();
}
}
}
}