C# 在windows应用商店应用程序中使用调度程序计时器进行图像幻灯片放映
我想在我的windows应用商店应用程序中使用dispatcher timer制作幻灯片图像。但是,我有一个问题:如果图像已到达最终图像,幻灯片放映不希望重复从第一个图像的幻灯片放映,而是直接从第二个图像。例如:我有5张图片,当它到达第五张图片时,幻灯片不想重复第一张图片,而是直接重复第二张图片 这是我的xaml:C# 在windows应用商店应用程序中使用调度程序计时器进行图像幻灯片放映,c#,image,windows-store-apps,windows-8.1,slideshow,C#,Image,Windows Store Apps,Windows 8.1,Slideshow,我想在我的windows应用商店应用程序中使用dispatcher timer制作幻灯片图像。但是,我有一个问题:如果图像已到达最终图像,幻灯片放映不希望重复从第一个图像的幻灯片放映,而是直接从第二个图像。例如:我有5张图片,当它到达第五张图片时,幻灯片不想重复第一张图片,而是直接重复第二张图片 这是我的xaml: <Image x:Name="sceneriesBtn" IsDoubleTapEnabled="False" VerticalAlignment="Bottom" Tappe
<Image x:Name="sceneriesBtn" IsDoubleTapEnabled="False" VerticalAlignment="Bottom" Tapped="sceneriesBtn_Tapped" Height="242" Stretch="UniformToFill"/>
下面是我的xaml.cs代码:
public Home()
{
this.InitializeComponent();
}
DispatcherTimer playlistTimer1 = null;
List<string> Images1 = new List<string>();
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ImageSource1();
}
private void ImageSource1()
{
Images1.Add("17-Ijen-Crater.jpg");
Images1.Add("19-Ranu-kumbolo-Semeru.jpg");
Images1.Add("30-Kelud-blitar.jpg");
Images1.Add("31-sarangan_lake.jpg");
Images1.Add("390-ranu_agung.jpg");
playlistTimer1 = new DispatcherTimer();
playlistTimer1.Interval = new TimeSpan(0, 0, 5);
playlistTimer1.Tick += playlistTimer_Tick1;
sceneriesBtn.Source = new BitmapImage(new Uri("ms-appx:///Sceneries/" + Images1[count1]));
playlistTimer1.Start();
}
int count1 = 0;
void playlistTimer_Tick1(object sender, object e)
{
if (Images1 != null)
{
if (count1 == Images1.Count - 1)
count1 = 0;
if (count1 < Images1.Count)
{
count1++;
ImageRotation1();
}
}
}
private void ImageRotation1()
{
sceneriesBtn.Source = new BitmapImage(new Uri("ms-appx:///Sceneries/" + Images1[count1].ToString()));
}
}
}
public Home()
{
this.InitializeComponent();
}
Dispatchermer playtimer1=null;
列表图像1=新列表();
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
ImageSource1();
}
私有void ImageSource1()
{
图1.添加(“17 Ijen陨石坑.jpg”);
图片1.添加(“19 Ranu kumbolo Semeru.jpg”);
图片1.添加(“30 Kelud blitar.jpg”);
图1.添加(“31-sarangan_lake.jpg”);
图片1.添加(“390-ranu_agung.jpg”);
PlayTimer1=新的调度程序();
playltimer1.Interval=新的时间跨度(0,0,5);
playltimer1.Tick+=playltimer_Tick1;
sceneriesBtn.Source=新位图图像(新Uri(“ms”)-appx:///Sceneries/“+Images1[count1]);
playlimer1.Start();
}
int count1=0;
void playlimer_Tick1(对象发送器,对象e)
{
if(Images1!=null)
{
if(count1==Images1.Count-1)
count1=0;
如果(计数1<图像1.计数)
{
count1++;
图像旋转1();
}
}
}
私有void ImageRotation1()
{
sceneriesBtn.Source=新位图图像(新Uri(“ms”)-appx:///Sceneries/“+Images1[count1].ToString());
}
}
}
如何修复它?逻辑缺陷。在代码中,计数器更改两次,首先从
Images1.Count-1
更改为0
,然后在第二条if语句中从0
增加为1
我的计划
if (count1 < Images1.Count)
count1++;
if (count1 >= Images1.Count)
count1 = 0;
ImageRotation1();
if(count1=Images1.Count)
count1=0;
图像旋转1();