uwp - UWP:如何在我的视图模型中获取轮播控件中使用的图像大小?
问题描述
我正在使用显示不同图像的轮播控件,我希望能够在我的视图模型中获取轮播中使用的图像的大小以进行一些计算。我该怎么做呢 ?
主页.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" 中的图像大小?
解决方案
您应该将 的 绑定ItemsSource
到Carousel
视图模型的集合属性,该属性返回表示要在视图中显示的图像的项目。
然后,您可以将视图中元素的Width
和Height
属性绑定Image
到该对象的相应源属性,就像您当前似乎将Source
目标属性绑定到Thumbnail
源属性一样。
因此,将Thumbnail
属性移动到表示图像或项目的新类,然后将Width
属性添加Height
到同一类并在 XAML 标记中绑定到它们。
推荐阅读
- javascript - 在 React Chart Js 2 中传递动态数据时的问题
- nativescript - 将特定于平台的组件导入到 nativescript angular 中的模块
- python - 辅助计算机上的 Pandas 例外
- java - 为什么在 ArrayDeque 和 Stack 中使用 push() 方法时输出不同?
- python - 找不到元素,请替换文本
- java - 找到这个序列的第 N 个数。两个设置位
- c# - 如何在网络流中写一个小间隙?
- solr - Solr json DSL 常数分数查询
- android - 构建项目时出现 CMake 错误
- command-line - 使用Java解压缩所有没有文件夹的文件