我有一个贴纸列表,我想从这个列表中选择一个或多个贴纸时,贴纸会在我的画布上显示在uwp应用程序中

时间:2016-06-02 08:07:24

标签: uwp-xaml

<ListView x:Name="Stickers1" Visibility="Collapsed" 
    SelectionChanged="Stickers1_SelectionChanged" 
    ScrollViewer.VerticalScrollMode="Enabled" 
    ScrollViewer.VerticalScrollBarVisibility="Hidden" BorderThickness="50" 
    FontSize="36" Margin="0" ItemTemplate="{StaticResource 
    listStickersDataTemplate}">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid Orientation="Horizontal" 
                HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>
 <DataTemplate x:Key="listStickersDataTemplate">
     <Grid>
         <Image Source="{Binding Imageurl}" Stretch="Fill" Height="200" Width="200"/>
    </Grid>
 </DataTemplate>`

1 个答案:

答案 0 :(得分:0)

查看您的Stickers1_SelectionChanged事件,您似乎无法在Source

中设置img Canvas

下面的内容应该修复它

private void Stickers1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var selecteditem = e.AddedItems[0] as StickersImageListModel;
    Stickers1.Visibility = Visibility.Collapsed;
    BitmapImage image = new BitmapImage(new System.Uri("ms-appx://" + selecteditem.ImageUrl, UriKind.Absolute));
    img.Source = image;
    my_canvas.Visibility = Visibility.Visible;   
}