know sth. new 大话C#的进阶必知点解析第1章 第5节 名贵中药材程序WPF显示图片报错,找不到资源? 什么原因

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

 

 1 Ui布局代码; 

    布局方面主要还是继承了原先的布局方式。包括图片的展示也是用了最外层border边框的方式边框加入背景颜色方式的图片展示; 去把目标图片进行显示出来这个没有太多技术含量。

   至于图片的路径自定义一个文件夹存放即可。

<Page x:Class="Wpf._2023DemoK.UiViewKTaiJieTwo.MingGuiZhongCaiYao_Page2"
      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:Wpf._2023DemoK.UiViewKTaiJieTwo"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="600"
      Title="MingGuiZhongCaiYao_Page2">
    <!--样式资源字典 1 -->
    <Page.Resources>
        <ResourceDictionary>
            <!--样式借用测试-->
            <Style x:Key="XiaoBtn" TargetType="Button">
                <Setter Property="Width" Value="190"/>
                <Setter Property="Height" Value="250"/>
                <Setter Property="VerticalContentAlignment" Value="Bottom"/>
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="FontSize" Value="24"/>
                <Setter Property="FontStretch" Value="Normal"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="FontFamily" Value="微软雅黑"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Cursor" Value="Hand"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary   Source="/01.StyleTongYongTemplate/AddTongYongDictionary10201.xaml"/>
                <ResourceDictionary   Source="/01.StyleTongYongTemplate/IsShiJianDictionary1.xaml"/>
                <ResourceDictionary   Source="/01.StyleTongYongTemplate/ListBoxDictionary.xaml"/>
                <ResourceDictionary   Source="/01.StyleTongYongTemplate/TextBlockDictionary.xaml"/>


            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>
    <!--最外层控件为边框; 界面背景图片的加入;自定义-->
    <Border>
        <Border.Background>
            <ImageBrush ImageSource="../../00.Image/NeiQianChengXu_Img/29.LongDan3.png"/>
        </Border.Background>
        <Grid>

        </Grid>
    </Border>
</Page>

2 后台代码;

  除了命名空间进行了修改之外其他的基本都是默认系统创建好的; 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wpf._2023DemoK.UiViewKTaiJieTwo
{
    /// <summary>
    /// MingGuiZhongCaiYao_Page2.xaml 的交互逻辑
    /// </summary>
    public partial class MingGuiZhongCaiYao_Page2 : Page
    {
        public MingGuiZhongCaiYao_Page2()
        {
            InitializeComponent();
        }
    }
}
 

 

 2.1 中间启动跑项目报错了几次;都是提示如下截图

   

 原因是

    没有把图片包含在项目中当然会报错的了 把放到文件夹里面的图片必须包含在项目里面才能展示。否则就是报错的。 包含后效果

   

 

  3 效果  ;

龙胆为例子;

 

中药材 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

“know sth. new 大话C#的进阶必知点解析第1章 第5节 名贵中药材程序WPF显示图片报错,找不到资源? 什么原因” 的相关文章