图像未显示在主窗口中,但显示在用户控件中

发布于 2025-01-16 22:21:07 字数 1612 浏览 2 评论 0 原文

  1. 在 WPF 项目中创建用户控件。

     
     <网格>
         
             <图像名称=“Heart1”
                    保证金=“8”
                    Source="pack://siteoforigin:,,, /Icons/nolike.png"
                    拉伸=“制服”
                    MouseDown=“Heart_MouseDown”
                    宽度=“40”
                    身高=“40”
                    >>
             <图片名称=“评论”
                    保证金=“8”
                    Source="pack://siteoforigin:,,,/Icons/comment.png"
                    拉伸=“制服”
                    宽度=“40”
                    身高=“35”
                    >>
             <图像名称=“发送”
                    保证金=“8”
                    Source="pack://siteoforigin:,,,/Icons/send.png"
                    拉伸=“制服”
                    宽度=“40”
                    身高=“35”
                    >>
         
         <图像名称=“书签”
                    水平对齐=“右”
                    保证金=“8”
                    Source="pack://siteoforigin:,,,/Icons/bookmark.png"
                    宽度=“40”
                    身高=“35”
                    >>
     
    
  2. 图像确实出现在用户控件中。

  3. 将用户控件包含在项目主窗口中,但图像消失了。

    输入 <本地:PostOperations Height =“60”> 这里

如何将用户控件中的图像显示到窗口?

  1. create a usercontrol in WPF project.

     <UserControl x:Class="Test1.PostOperations"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Test1"
              mc:Ignorable="d" 
              d:DesignHeight="50" d:DesignWidth="500">
     <Grid>
         <StackPanel Orientation="Horizontal">
             <Image Name="Heart1"
                    Margin="8"
                    Source="pack://siteoforigin:,,, /Icons/nolike.png"
                    Stretch="Uniform"
                    MouseDown="Heart_MouseDown"
                    Width="40"
                    Height="40"
                    />
             <Image Name="Comment"
                    Margin="8"
                    Source="pack://siteoforigin:,,,/Icons/comment.png"
                    Stretch="Uniform"
                    Width="40"
                    Height="35"
                    />
             <Image Name="Send"
                    Margin="8"
                    Source="pack://siteoforigin:,,,/Icons/send.png"
                    Stretch="Uniform"
                    Width="40"
                    Height="35"
                    />
         </StackPanel>
         <Image Name="bookmark"
                    HorizontalAlignment="Right"
                    Margin="8"
                    Source="pack://siteoforigin:,,,/Icons/bookmark.png"
                    Width="40"
                    Height="35"
                    />
     </Grid>
    
    1. Images do appear in usercontrol.

    2. include the usercontrol in the project mainwindow but the image disappeared.

      enter

      <local:PostOperations Height="60">
      </local:PostOperations>

      here

how to show the image in the usercontrol to a windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-01-23 22:21:07
pack://siteoforigin:,,,/Icons/send.png

与启动应用程序的可执行程序集的位置相关。

如果您的 UserControl 和 MainWindow 不在同一程序集中,请确保它们位于同一路径中

pack://siteoforigin:,,,/Icons/send.png

is relative to the location from which the application's executable assembly is launched.

if your UserControl and MainWindow are not in the same assembly, make sure they are in the same path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文