我有一个场景,我必须制作一个幻灯片放映按钮,我已经尝试了很多但无法制作幻灯片。
Image img = new Image();
string path = System.AppDomain.CurrentDomain.BaseDirectory + "chart2 - Copy.png";
img.Source = new BitmapImage(new Uri(path));
StackPanel stackPnl = new StackPanel();
stackPnl.Orientation = Orientation.Horizontal;
stackPnl.Margin = new Thickness(10);
stackPnl.Children.Add(img);
button1.Content = stackPnl;
答案 0 :(得分:0)
尝试在MVVM中轻松实现。 我正在给出一个想法或模拟如何执行它。
<Button Height="200" Width="200">
<ControlTemplate>
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding ImageURI}" />
</Image.Source>
</image>
</ControlTemplate>
</Button>
private string _ImageURI = "";// add the path of your image in the quotes
public string ImageURI { get { return _ImageURI; } set { _ImageURI = value; NotifyPropertyChanged(); } }
public void SlideShow()
{
DispatcherTimer DT = new DispatcherTimer();
DT.Tick += DT_Tick;
DT.Interval = new TimeSpan(0, 0, 1);
DT.Start();
}
private void DT_Tick(object sender, EventArgs e)
{
// Change your image uri here 'ImageURI'
}
在SlideShow()
或您想要的任何地方拨打VM constructor
。