亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

圖像未顯示在用戶控件中

圖像未顯示在用戶控件中

C#
心有法竹 2022-08-20 16:10:33
我已經找到了很多關于這個問題的答案,但無論我嘗試什么,似乎都不起作用。我正在嘗試在 UWP 應用程序中創建用戶控件。用戶控件由邊框組成,邊框內有圖像和文本塊。我設法讓TextBlock文本顯示出來,但無論我做什么,我似乎都無法獲得圖像顯示在UserControl中。到目前為止,事情已經嘗試過:將“圖形屬性類型”更改為“圖像”、“圖像源”和“Uri”。將邊框中的圖像放入內容預覽中。在這一點上,我不記得其他事情。我不知道如何讓它工作。我知道我以前做過這件事,但那是幾年前的事了,我顯然已經意識到了如何(或者UWP發生了重大變化,因為我的大部分經驗都是在WPF中)。有人可以幫忙找到我在哪里搞砸了嗎?用戶控制 XAML:<UserControl    x:Class="ShirtSleeves.CardControlxaml"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:local="using:ShirtSleeves"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    x:Name="CardControl"    mc:Ignorable="d"    d:DesignHeight="400"    d:DesignWidth="300">    <Grid>        <Border Margin="0,10" Background="White" BorderBrush="Black" BorderThickness="5" Width="260" Height="352" CornerRadius="20">            <Grid>                <Grid.RowDefinitions>                    <RowDefinition Height="Auto"/>                    <RowDefinition Height="Auto" />                </Grid.RowDefinitions>                <Image Source="{Binding ElementName=CardControl, Path=Graphic}" Height="200" Width="200" HorizontalAlignment="Center" VerticalAlignment="Bottom" />                <TextBlock Text="{Binding ElementName=CardControl, Path=Label}" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,30" Foreground="Black" FontSize="48" FontWeight="Bold" />            </Grid>        </Border>    </Grid></UserControl>
查看完整描述

1 回答

?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

UWP 不允許直接訪問應用容器外部的文件。這意味著您無法像這樣設置圖像源。C:\Users\<username>\source\repos\ShirtSleeves\ShirtSleeves\Images\Rook (Games).png

在您的例子中,最簡單的方法是將圖像放入項目的 Assets 文件夾中,如下所示:

http://img1.sycdn.imooc.com//63009718000101cb01990101.jpg

然后,您可以指定“圖形”屬性,如下所示:

<local:CardControlxaml Label="Search" Graphic="Assets/animals.jpg" Foreground="Black" />

有關詳細信息,請閱讀文件訪問權限。


查看完整回答
反對 回復 2022-08-20
  • 1 回答
  • 0 關注
  • 85 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號