设置Source后,Image ActualWidth / ActualHeight不会直接显示 [英] Image ActualWidth/ActualHeight not displayed directly after setting Source

查看:129
本文介绍了设置Source后,Image ActualWidth / ActualHeight不会直接显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 我有可供选择的图像。
- 选择图像然后将图像加载到编辑区域。
- 为了使图像居中,我需要获得ActualWidth / ActualHeight属性。

问题:设置图像源时,实际显示图像需要一段时间。我只能在加载/显示时获取这些属性。

现在我正在使用DispatchTimer等到ActualWidth的值大于0.0。我从另一个方法调用以下DispatcherTimer(在ctor初始化方法中声明)(实际代码包含更多行):


 CenterPictureTimer =  new  DispatcherTimer(); 
CenterPictureTimer.Interval = new TimeSpan(0,0,0,0,20);
CenterPictureTimer.Tick + =( object sender,EventArgs e)=> {
if (ImageControl.PictureActualWidth == 0.0)
return ;

CenterPicture();
ImageControl.BeginPictureFadeIn();
CenterPictureTimer.Stop();
};


解决方案

Hi Ray,



- I have images to select from.
- Selecting the image should then load the image into an editing area.
- For centering the image I need to get the ActualWidth/ActualHeight properties.

The problem: When setting the image source, it takes a while until the image is actually displayed. I can only get those properties when it got loaded/displayed.

Right now I'm using a DispatchTimer to wait until the ActualWidth has a value above 0.0. and I call the following DispatcherTimer (declared in a ctor Initialize-method) from another method (real code contains more lines):

CenterPictureTimer = new DispatcherTimer();
CenterPictureTimer.Interval = new TimeSpan(0,0,0,0,20);
CenterPictureTimer.Tick += (object sender,EventArgs e) => {
    if (ImageControl.PictureActualWidth == 0.0)
        return;

    CenterPicture();
    ImageControl.BeginPictureFadeIn();
CenterPictureTimer.Stop(); };

解决方案

Hi Ray,



这篇关于设置Source后,Image ActualWidth / ActualHeight不会直接显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆