【问题标题】:Image ComboBox XAML not displaying properly during runtimeImage ComboBox XAML 在运行时未正确显示
【发布时间】:2015-07-28 09:04:59
【问题描述】:

我正在尝试实现一个只有图像的组合框。图像不需要是动态的。我目前正在这样做:

<ComboBox HorizontalAlignment="Center" x:Name="diceDot" Canvas.Left="244" Canvas.Top="10" Height="20" Width="40">
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice1.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice2.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice3.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice4.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice5.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                    <ComboBoxItem>
                        <Image Stretch="Fill" Source="Resources/dice6.png" Height="20" Width="20"></Image>
                    </ComboBoxItem>
                </ComboBox>

但是,图像在运行时没有出现。在设计过程中,它确实完美地呈现了预期的结果。我不希望包含图像的文件夹与我的可执行文件一起出现。

错误:

A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll

已编辑:添加错误消息

问题已解决 - 将构建操作更改为“资源”并重新构建解决方案似乎可以解决问题。

【问题讨论】:

  • 进入图片的VS属性选项卡,他们选择了什么“构建动作”?这些引用必须是“内容”才能起作用。
  • 我认为它应该是资源或嵌入资源。但是,我已切换到 Content,但它在运行时仍然不显示我的图像。
  • 在输出窗口中查找错误。听起来图像的路径是错误的。
  • @GazTheDestroyer 是的。输出表明图像的路径错误。
  • @almulo 啊。构建操作需要是“资源”而不是“内容”。

标签: c# wpf xaml combobox


【解决方案1】:

问题已解决 - 将构建操作更改为“资源”并重新构建解决方案似乎可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 2023-03-04
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多