如何动态更改ImageBrush?

时间:2017-12-29 23:51:02

标签: c# wpf

以下是一些不起作用的代码:

XAML:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   // work fine
   image_background.ImageSource = CreateBitmapSource(System.Windows.Media.Color.FromArgb(255, 0, 255, 0));
}

C#:(无法动态更改图片。)

System.Windows.Application.Current.Dispatcher.Invoke(
    DispatcherPriority.Background,
    new Action(() => image_background.ImageSource = CreateBitmapSource(System.Windows.Media.Color.FromArgb(255, 0, 255, 0))));

不改变图像,任何解决方案?

这是可以正常运行的代码。

        questionLoader = new Loader();
        var questionRequest:URLRequest = new URLRequest(xmlName);
        questionLoader.load(questionRequest);
        questionLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);

 public function swfLoaded(e:Event) {

        var target: MovieClip = e.currentTarget.content;
        trace(target);

        addChild(target);
        target.externalFun();
    }

更新:

   public function LoadedFile() {
        // constructor code

        this.addEventListener(Event.ADDED_TO_STAGE,init);

    }

    public function externalFun():void {

    trace("IT WORKS");

    }

0 个答案:

没有答案