SetFocusedIndexSync(Int32) Метод (WpfImageViewer)
Синхронно устанавливает новое значение свойства
FocusedIndex.
Вот C#/VB.NET код, который демонстрирует, как запустить анимацию в WpfImageViewer, если изображения хранятся в Images.
''' <summary>
''' Starts showing animation in image viewer.
''' </summary>
''' <param name="viewer">An image viewer.</param>
''' <param name="delay">The animation delay in milliseconds.</param>
Private Sub StartAnimation(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer, delay As Integer)
' start animation
System.Threading.ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf ShowAnimation), New Object() {viewer, delay})
End Sub
''' <summary>
''' Shows animation in image viewer.
''' </summary>
''' <param name="state">Data that the method uses.</param>
Private Sub ShowAnimation(state As Object)
' get data
Dim data As Object() = DirectCast(state, Object())
' get image viewer
Dim viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer = DirectCast(data(0), Vintasoft.Imaging.Wpf.UI.WpfImageViewer)
' get delay value
Dim delay As Integer = CInt(data(1))
' for each image in image collection of image viewer
For i As Integer = 0 To viewer.Images.Count - 1
' change image in image viewer
viewer.SetFocusedIndexSync(i)
' sleep for a while
System.Threading.Thread.Sleep(delay)
Next
End Sub
/// <summary>
/// Starts showing animation in image viewer.
/// </summary>
/// <param name="viewer">An image viewer.</param>
/// <param name="delay">The animation delay in milliseconds.</param>
private void StartAnimation(Vintasoft.Imaging.Wpf.UI.WpfImageViewer viewer, int delay)
{
// start animation
System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(ShowAnimation), new object[] { viewer, delay });
}
/// <summary>
/// Shows animation in image viewer.
/// </summary>
/// <param name="state">Data that the method uses.</param>
private void ShowAnimation(object state)
{
// get data
object[] data = (object[])state;
// get image viewer
Vintasoft.Imaging.Wpf.UI.WpfImageViewer viewer =
(Vintasoft.Imaging.Wpf.UI.WpfImageViewer)data[0];
// get delay value
int delay = (int)data[1];
// for each image in image collection of image viewer
for (int i = 0; i < viewer.Images.Count; i++)
{
// change image in image viewer
viewer.SetFocusedIndexSync(i);
// sleep for a while
System.Threading.Thread.Sleep(delay);
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5