2013-04-08 147 views
0

我是一个WPF新手。在我的WPF应用程序中,我有从网络加载的图像。为了避免gui阻塞,我遵循How can I keep a WPF Image from blocking if the ImageSource references an unreachable Url?显示默认本地图像,而URL图像加载

中提到的方法。问题是,在图像加载之前,gui不遵守图像节点中设置的尺寸属性。最终的结果是一种“调整大小”的影响 - 最初gui(元素)是一种尺寸,一旦加载图像就会“重新调整”。

我希望使负载“平稳”。我希望能够指定一个'初始默认'图像。类似于initial image in WPF Image Control

但是我无法让它工作。可能是下面ImageAsyncHelper(这显然是错误的):

public static readonly DependencyProperty SourceUriProperty = DependencyProperty.RegisterAttached("SourceUri", typeof(Uri), typeof(ImageAsyncHelper), new PropertyMetadata 
    { 
     PropertyChangedCallback = (obj,e) => 
     { 
      ((Image)obj).SetBinding(Image.SourceProperty, 
       new Binding("DefaultUri") 
       { 
        Source = new Uri("pack://application:,,,/blah/Images/Default.gif", UriKind.RelativeOrAbsolute) 
       }); 

     } 

     PropertyChangedCallback += (obj, e) => 
     { 
      ((Image)obj).SetBinding(Image.SourceProperty, 
       new Binding("VerifiedUri") 
       { 
        Source = new ImageAsyncHelper { GivenUri = (Uri)e.NewValue }, 
        IsAsync = true, 
       }); 
     } 
    }); 

我有什么选择?

+0

也许你应该得到一个WPF内存的图像,你不必担心休息。 – Dilshod 2013-04-09 00:35:12

+0

你在建立一个WPF控件吗?你是否绑定到XAML中的图像? – 2013-04-09 06:02:32

+0

你说你想让过渡顺利。你的意思是你想要最初的图像和取得的图像是相同的大小?您是否打算显示默认图像,直到真实图像准备好? – 2013-04-09 06:05:26

回答

0

尝试将图像元素MinWidth和MaxWidth设置为所需的大小。

相关问题