图像组合框XAML在运行时不能正确显示

本文关键字:不能 显示 运行时 组合 XAML 图像 | 更新日期: 2023-09-27 18:04:58

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

<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

编辑:添加错误信息

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

图像组合框XAML在运行时不能正确显示

问题已修复-将构建操作更改为"Resource"并重新构建解决方案似乎解决了问题。