返回首页

您好

我想创建一个WPF中的图像控制,但在运行时,无法在页面上显示任何图片,任何人都可以帮助在运行时改变图像的循环。下面是我的代码: -


 string[] imgs = new string[]{ "print1.png", "print2.png", "print3.png", "print4activation-click.png"};

 string[] caption = new string[] { "Picture1", "Picture2", "Picture3", "Picture4"};

 private int selected = 0;

 private string _threadOutput = "";

 public readonly SynchronizationContext mySynchronizationContext; 

 bool _stopThreads = false;

 

 public MainWindow()

        {

            InitializeComponent();

            mySynchronizationContext = SynchronizationContext.Current; 

        } 

 

private void Window_Loaded(object sender, RoutedEventArgs e)

        {

            Thread thread1 = new Thread(new ThreadStart(DisplayThread1));

            thread1.SetApartmentState(ApartmentState.STA);

            thread1.IsBackground = true;

            thread1.Start();

        }

 

 void DisplayThread1()

        {

            while (_stopThreads == false)

            {

                if (selected == 0)

                {

                    selected = imgs.Length - 1;

                    showImage(imgs[selected], selected);

                }

                else if (selected == imgs.Length - 1)

                {

                    selected = 0;

                    showImage(imgs[selected], selected);

                }

                else

                {

                    selected = selected + 1;

                }

            }

        }

 

private void showImage(string img, int i)

        {

            BitmapImage b1 = new BitmapImage();

            b1.BeginInit();

            b1.UriSource = new Uri(img,UriKind.RelativeOrAbsolute);

            b1.EndInit();

            b1.Freeze();

            SendOrPostCallback callback = _ =>

                {

                    Action action = delegate {image1.Source = b1;};

                    image1.Dispatcher.Invoke(action);

                };

            mySynchronizationContext.Send(callback, null); 

        }

回答

评论会员:DaveAuld 时间:2012/02/04
首先,您需要进行身份验证与Facebook

并且可以使用传统的setStatus做实际更新;
{A}]:约翰・西蒙斯/取缔程序员
评论会员:游客 时间:2012/02/04
谷歌透露:{A2的}]