繁体   English   中英

WPF-图片未显示

[英]WPF - Image not showing up

我有我的应用程序,现在我想添加一个关闭按钮。 我在设计器中使用图像创建了它(也许有更好的方法!如果可以,请回答),一切似乎都可以正常工作: 一些形象

然后我运行该应用程序,它看起来像这样:

另一个人在这里

为什么不再有按钮/图像? 我不知道! 顺便说一句,图片是.png并保存在资源中!

我的WPF代码:

<Window x:Class="Chat_App.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="500" Width="1000" WindowStyle="None" AllowsTransparency="True">
    <Window.Background>
        <RadialGradientBrush>
            <GradientStop Color="#FF323A44" Offset="1"/>
            <GradientStop Color="#FF384A5A"/>
        </RadialGradientBrush>
    </Window.Background>

    <Grid>
        <Border BorderThickness="1" Height="26" VerticalAlignment="Top" Background="#FF436B85" MouseLeftButtonDown="Border_MouseLeftButtonDown">
            <Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="33" Source="pack://siteoforigin:,,,/Resources/simat_btn_chat.png" MouseLeftButtonDown="Image_MouseLeftButtonDown" Margin="963,2,0,0"/>
        </Border>
    </Grid>
</Window>

顺便说一句,我也尝试了一个ico文件!

谢谢!

删除图像的verticalAlighment和horizo​​ntalAlignment并将其包裹在网格中,应该像这样,

<Border BorderThickness="1" Height="26" VerticalAlignment="Top" Background="#FF436B85">
 <Grid HorizontalAlignment="Right" Width="24">
 <Image Source="Images/download.jpg"  Margin="0,0,0,0" d:LayoutOverrides="Width"/>
</Grid>
</Border>

这是输出

尝试将其添加为资源(也启用可重用性!)

<Window.Resources>
     <Image x:Key="MyImage" Source.../>
</Window.Resources>

然后在您的网格中将其用作:

<Button Content={StaticResource MyImage} />

另外,请确保将您的图片构建为Resource

编辑:该按钮显示,但不是您的图像。 因此无法正确找到它。 尝试更改您的包网址。

要么喜欢,

Source="pack://application:,,,/Resources/simat_btn_chat.png"

要么

Source="/Resources/simat_btn_chat.png"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM