首页 > 其他分享 >WPF relative uri

WPF relative uri

时间:2024-09-30 20:50:24浏览次数:10  
标签:Windows uri jpg System relative Source new using WPF

 <Image Grid.Column="0" 
        Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="1" 
        Source="pack://application:,,,/Images/1.jpg"
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="2" 
        Source="/Images/1.jpg" 
        RenderOptions.BitmapScalingMode="Fant"/>
 <Image Grid.Column="3" x:Name="img" 
        RenderOptions.BitmapScalingMode="Fant"/>


//cs
img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));

 

Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"



Source="pack://application:,,,/Images/1.jpg"



Source="/Images/1.jpg"


img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));

 

 

 

 

//xaml
<Window x:Class="WpfApp431.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp431"
        mc:Ignorable="d"
        WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Image Grid.Column="0" 
               Source="pack://application:,,,/WpfApp431;component/Images/1.jpg"
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="1" 
               Source="pack://application:,,,/Images/1.jpg"
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="2" 
               Source="/Images/1.jpg" 
               RenderOptions.BitmapScalingMode="Fant"/>
        <Image Grid.Column="3" x:Name="img" 
               RenderOptions.BitmapScalingMode="Fant"/>
    </Grid>
</Window>


//cs
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 WpfApp431
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/1.jpg"));
        }
    }
}

 

标签:Windows,uri,jpg,System,relative,Source,new,using,WPF
From: https://www.cnblogs.com/Fred1987/p/18442421

相关文章

  • WPF mutex single instance
    privatestaticMutexmtx=null;publicMainWindow(){boolisCreateNew;stringappName=System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);mtx=newMutex(true,appName,outisCreateNew);if(!isCreate......
  • WPF Calendar DisplayMode SelectionMode FirstDayOfWeek Start End BlackoutDates
    //xaml<Windowx:Class="WpfApp427.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • WPF slider IsSelectionRangeEnabled TickFrequency
    <Windowx:Class="WpfApp426.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft......
  • wpf 找不到资源 *.xaml 字典文件异常处理
    找不到字典时设置如下<ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionarySource="/Themes/1.xaml"/><ResourceDictionarySource="/Themes/2.xaml"......
  • WPF MVVM入门系列教程(二、依赖属性)
    说明:本文是介绍WPF中的依赖属性功能,如果对依赖属性已经有了解了,可以浏览后面的文章。 为什么要介绍依赖属性在WPF的数据绑定中,密不可分的就是依赖属性。而MVVM又是跟数据绑定紧密相连的,所以在学习MVVM之前,很有必须先学习一下依赖属性。 依赖属性(DepencencyProperty)是什......
  • WPF Progrss bar stringformat {} {0}% IsDetermined
    //xaml<Windowx:Class="WpfApp425.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......
  • (二)WPF布局
    <Windowx:Class="WpfTest.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.c......
  • spring security 超详细使用教程(接入springboot、前后端分离)
    SpringSecurity是一个强大且可扩展的框架,用于保护Java应用程序,尤其是基于Spring的应用。它提供了身份验证(验证用户身份)、授权(管理用户权限)和防护机制(如CSRF保护和防止会话劫持)等功能。SpringSecurity允许开发者通过灵活的配置实现安全控制,确保应用程序的数据和资......
  • WPF下使用FreeRedis操作RedisStream实现简单的消息队列
    RedisStream简介RedisStream是随着5.0版本发布的一种新的Redis数据类型:高效消费者组:允许多个消费者组从同一数据流的不同部分消费数据,每个消费者组都能独立地处理消息,这样可以并行处理和提高效率。阻塞操作:消费者可以设置阻塞操作,这样它们会在流中有新数据添加时被唤醒并开始......
  • .NET|--WPF|--笔记合集|--依赖项属性|--5.附加属性
    前言附加属性是一个ExtensibleApplicationMarkupLanguage(XAML)概念。附加属性允许为派生自DependencyObject的任何XAML元素设置额外的属性/值对,即使该元素未在其对象模型中定义这些额外的属性。额外的属性可进行全局访问。附加属性通常定义为没有常规属性包装......