【发布时间】:2013-05-09 00:05:55
【问题描述】:
我创建了一个UserControl,其中包含一个Grid,其中包含一个Image-控件。
<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(从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);
}
为了确保我的UserControl 被附加到布局容器中,我将Grid 的Background 设置为白色,它显示得很好。我还将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 将显示出来。这里有什么问题?
【问题讨论】:
-
原谅我的提问,但你问的是什么问题?
-
@JerryNixon-MSFT using .NET/C# 我习惯于相对简单的分配,我也缺乏 WPF 知识。我预计,如果我简单地将
Image-control-reference 分配给我的UserControl的Image,它将正确显示,但如果我使用我的第一种方法,则没有任何显示。我只是不明白为什么它不显示... -
使用 C# 吧?在我看来更像 C++/CX。话虽如此,您是否要将新图像添加到
Container.Children集合中,以便将其包含在 XAML 可视化树中? -
标记正确/最佳答案是有礼貌的。
-
对不起,我以为我做到了......
标签: user-controls windows-runtime winrt-xaml c++-cx