UWP:如何获取视图模型中旋转木马控件中使用的图像大小?

UWP:如何获取视图模型中旋转木马控件中使用的图像大小?,uwp,uwp-xaml,Uwp,Uwp Xaml,我正在使用一个显示不同图像的旋转木马控件,我希望能够在我的视图模型中获得旋转木马中使用的图像的大小,以便进行一些计算。我该怎么做 MainPage.xaml <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls=&

我正在使用一个显示不同图像的旋转木马控件,我希望能够在我的视图模型中获得旋转木马中使用的图像的大小,以便进行一些计算。我该怎么做

MainPage.xaml

 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d">

 <Grid>
<Border Margin="0">
  <controls:Carousel x:Name="CarouselControl"
              InvertPositive="True"
              ItemDepth="300"
              ItemMargin="340"
              ItemRotationX="0"
              ItemRotationY="45"
              ItemRotationZ ="0"
              Orientation="Horizontal"
              SelectedIndex="4">
    <controls:Carousel.EasingFunction>
      <CubicEase EasingMode="EaseOut" />
    </controls:Carousel.EasingFunction>
    <controls:Carousel.ItemTemplate>
      <DataTemplate>
        <Image 
              x:Name ="Images"
              Width="200"
              Height="200"
              VerticalAlignment="Bottom"
              Source="{Binding Thumbnail}"
              Stretch="Uniform" />
      </DataTemplate>
    </controls:Carousel.ItemTemplate>
  </controls:Carousel>
</Border>

如何访问此xaml页面视图模型中x:Name=“images”中图像的大小

如何访问此xaml页面视图模型中x:Name=“images”中图像的大小

所以你想得到你使用的所有图像的大小值,对吗

您用来绑定的缩略图是什么,它是指向图像的Uri吗?如果它是一个Uri,要获取本地文件的大小,可以使用该Uri创建一个,然后使用一个Uri获取宽度和高度

以下是您可以参考的代码示例:

   StorageFile sf =  await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/london.png"));
        BitmapDecoder dec = await BitmapDecoder.CreateAsync(await sf.OpenAsync(FileAccessMode.Read));
        var width = dec.PixelWidth;
        var height = dec.PixelHeight;

您应该将
Carousel
ItemsSource
绑定到视图模型的集合属性,该属性返回表示要在视图中显示的图像的项目

然后,您可以将视图中
图像
元素的
宽度
高度
属性绑定到此对象的相应源属性,就像您当前似乎将
目标属性绑定到
缩略图
源属性一样

因此,将
缩略图
属性移动到表示图像或项目的新类,然后将
宽度
高度
属性添加到同一类,并在XAML标记中绑定到它们