【问题标题】:Is it possible to get Image elements to render in the XAML designer for Visual Studio 2019?是否可以在 Visual Studio 2019 的 XAML 设计器中呈现图像元素?
【发布时间】:2019-10-31 16:32:03
【问题描述】:

我在 Visual Studio 2019 的设计时无法再看到绑定到 XAML 元素的图像。相同的代码在 Visual Studio 2017 设计器中正确显示图像。 p>

有人知道是否有设置或技术可以在 2019 年渲染图像吗?或者知道这可能是一个新的“错误”或“功能”吗?

我确实使用 XAML 热重载。但是我的 UI 的某些元素依赖于围绕特定宽度和高度的图像进行布局,当显示代表性图像时,在设计器中进行更改会容易得多。

【问题讨论】:

  • 您是否尝试使用Pack URIs in WPF 来加载图片资源?像 Source="pack://application:,,,/imgss/Gakuse-Folder.ico" 很难检测出导致这个问题的原因。可以分享更多相关代码。
  • 我正在绑定到 ViewModel 中的 ImageSource。实际上,图像源是从实例化设计时视图模型的代码中的 URI 加载的。同样,完全相同的代码在 Visual Studio 2017 中运行。

标签: wpf visual-studio xaml visual-studio-2019


【解决方案1】:

原来这是bug。已修复且待发布。

【讨论】:

    【解决方案2】:

    如果您在实例化设计时视图模型的代码中从 URI 加载图像。它不会在 Visual Studio 设计器中显示图像。

    <Window.DataContext>
        <local:ImagesDetailsviewmodel/>
    </Window.DataContext>
    
      <Image x:Name="image" Grid.Row="0"
           Grid.ColumnSpan="3" Height="100" Source="{Binding ImaUrlName}" Width="100"/>
    
     public class ImagesDetailsviewmodel
    {
        public ImagesDetailsviewmodel()
        {
            imaUrlName = "pack://application:,,,/imagess/test001.jpg";
        }
    
        private string imaUrlName;
        public string ImaUrlName
        {
            get
            {
                return imaUrlName;
            }
            set
            {
                imaUrlName = value;
            }
        }
    }
    

    您可以直接使用 xaml 代码在设计器中显示图像。

      <Image x:Name="image22" Grid.Row="0"
           Grid.ColumnSpan="3" Height="100" Source="pack://application:,,,/imagess/test002.jpg" Width="100"/>
    

    'Write and debug running XAML code with XAML Hot Reload in Visual Studio' 可以帮助您在运行应用时更改 XAML 代码。

    此外,您可以分享更多相关信息并前往Developer Community Visual Studio 并报告您的问题。

    【讨论】:

    • 是的,这基本上证实了我在原始问题中所说的话。在我的 XAML 中拥有静态图像路径并不是什么好事。我已经按照建议向 Visual Studio 开发者社区提交了一个案例,如果有任何进展,我会在此处更新。
    猜你喜欢
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2017-01-24
    • 2021-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 1970-01-01
    相关资源
    最近更新 更多