我创建了一个由 aUserControl
组成的,Grid
其中包含一个Image
-control。
<UserControl
x:Class="Album.AlbumPicture"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Album"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
Width="200"
Height="200"
>
<Grid Width="200" Height="200">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Name="AlbumPictureImage" Width="200" Height="200" Grid.Column="0" Grid.Row="0" />
</Grid>
</UserControl>
现在,我有一个构造函数,它采用现有的Image
(从 a 新创建的Stream
)并将 分配Image
给我的自定义控件Image
AlbumPicture::AlbumPicture(Windows::UI::Xaml::Controls::Image^ Image){
InitializeComponent();
this->AlbumPictureImage = Image;
this->Height = 200;
this->Width = 200;
this->state = AlbumPictureState::SWIPE;
this->StartingPoint = Point(0,0);
}
为了确保 myUserControl
被附加到布局容器中,我制作了Background
白色的Grid
,它显示得很好。我还Image
直接将其添加到布局容器中,并且显示正确。
现在,当我将构造函数更改为
AlbumPicture::AlbumPicture(Windows::UI::Xaml::Media::ImageSource^ Source){
InitializeComponent();
this->AlbumPictureImage->Source = Source;
this->Height = 200;
this->Width = 200;
this->state = AlbumPictureState::SWIPE;
this->StartingPoint = Point(0,0);
}
一切正常,Image
将显示。这里有什么问题?