WPF-13:资源文件需要手动引用问题
生活随笔
收集整理的這篇文章主要介紹了
WPF-13:资源文件需要手动引用问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近碰到一個(gè)問(wèn)題。
兩個(gè)自定義控件,其中用到圖片,即<Image Source="圖片路徑" />。
控件1:
<UserControl x:Class="TestImageSource.UserControl1" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Image Source="TestImageSource;component/Images/laugh.gif" /> </Grid> </UserControl>
控件2:
<UserControl x:Class="TestImageSource.UserControl2" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Image Source="/TestImageSource;component/Images/laugh.gif" /> </Grid> </UserControl>
調(diào)用該控件:
<Window x:Class="TestImageSource.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="520" Width="1022" xmlns:my="clr-namespace:TestImageSource"> <Grid> <my:UserControl1 HorizontalAlignment="Left" Margin="21,12,0,0" x:Name="userControl11" VerticalAlignment="Top" Height="267" Width="423" /> <my:UserControl2 HorizontalAlignment="Left" Margin="540,58,0,0" x:Name="userControl21" VerticalAlignment="Top" Height="320" Width="411" /> </Grid> </Window>
區(qū)別在于第一個(gè)控件的Source="TestImageSource;component/Images/laugh.gif" 是手動(dòng)填寫。第二個(gè)則是,屬性-source-選擇圖片。
結(jié)果造成,作為控件使用時(shí),控件1無(wú)法顯示圖片,控件2正常顯示圖片。如下:
兩個(gè)自定義控件,其中用到圖片,即<Image Source="圖片路徑" />。
控件1:
<UserControl x:Class="TestImageSource.UserControl1" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Image Source="TestImageSource;component/Images/laugh.gif" /> </Grid> </UserControl>
控件2:
<UserControl x:Class="TestImageSource.UserControl2" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <Image Source="/TestImageSource;component/Images/laugh.gif" /> </Grid> </UserControl>
調(diào)用該控件:
<Window x:Class="TestImageSource.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="520" Width="1022" xmlns:my="clr-namespace:TestImageSource"> <Grid> <my:UserControl1 HorizontalAlignment="Left" Margin="21,12,0,0" x:Name="userControl11" VerticalAlignment="Top" Height="267" Width="423" /> <my:UserControl2 HorizontalAlignment="Left" Margin="540,58,0,0" x:Name="userControl21" VerticalAlignment="Top" Height="320" Width="411" /> </Grid> </Window>
區(qū)別在于第一個(gè)控件的Source="TestImageSource;component/Images/laugh.gif" 是手動(dòng)填寫。第二個(gè)則是,屬性-source-選擇圖片。
結(jié)果造成,作為控件使用時(shí),控件1無(wú)法顯示圖片,控件2正常顯示圖片。如下:
不知是本地環(huán)境有問(wèn)題還是原本如此,所以同樣使用的需要注意了,還是手動(dòng)選擇圖片吧。
代碼下載:http://download.csdn.net/detail/yysyangyangyangshan/5234502
總結(jié)
以上是生活随笔為你收集整理的WPF-13:资源文件需要手动引用问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 使用JavaScript动态添加复选框C
- 下一篇: SDRAM芯片初始化、行有效、列读写时序