WPF Image Source 路徑4種常用方式


 
         
<Window
    x:Class="WpfApp1.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:local="clr-namespace:WpfApp1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Button Grid.Row="0">
            <Image Source="img/a.png" />
        </Button>
        <Button Grid.Row="1">

            <Image Source="/WpfApp1;component/img/a.png" />
        </Button>
        <Button Grid.Row="2">
            <StackPanel>
                <TextBlock Text="pack Url" />
                <Image Source="pack://application:,,,/img/a.png" />
            </StackPanel>
        </Button>
        <Button Grid.Row="3">
            <StackPanel>
                <TextBlock Text="pack Url 引用別的程序集資源" />
                <Image Source="pack://application:,,,/WpfApp1;component/img/a.png" />
            </StackPanel>
        </Button>
    </Grid>
</Window>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM