当我从UWP Community Toolkit轮播控件中按下图像时,我试图选择该项。
以下是我的xaml:
<Page.Resources>
<DataTemplate x:Key="photos">
<Grid Background="White" BorderBrush="Black" BorderThickness="1">
<Image Source="{Binding CItem}" Width="300" Height="300" Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</Page.Resources>
<Grid Row="1" Grid.RowSpan="2" Grid.Column="2" Grid.ColumnSpan="2" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="tblTitle" HorizontalAlignment="Center" Margin="0,0,0,0" TextWrapping="Wrap" Text="Swipe to fond your Template" VerticalAlignment="Top" FontWeight="Bold" />
<Border Margin="0,0,0,0">
<Custom:Carousel x:Name="CaroTest" InvertPositive="True" ItemDepth="300" KeyDown="Go_KeyDown" ItemMargin="19" ItemRotationX="43" ItemRotationY="65" ItemRotationZ="42" Orientation="Horizontal" ItemTemplate="{StaticResource photos}" SelectedIndex="2" SelectionChanged="CaroTest_SelectionChanged" >
<Custom:Carousel.EasingFunction>
<CubicEase EasingMode="EaseOut" />
</Custom:Carousel.EasingFunction>
</Custom:Carousel>
</Border>
</Grid>
下面是我的事件处理程序代码:
private void CaroTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
CaroItem lbi = ((sender as CaroItem).CItem as CaroItem);
var result1 = " You selected " + lbi.CItem.ToString() + ".";
var result = CaroTest.SelectedIndex.ToString();
}
我遇到以下错误:
严重性代码描述项目文件行抑制状态 错误CS0039无法通过引用转换,装箱转换,拆箱转换,换行转换或空类型转换EMRTest1 C:\ Projects2018 \ EMRTest1 \ EMRTest1 \ Views \ MainPage.xaml将类型'string'转换为'EMRTest1.Views.CaroItem'。 cs 217有效
Selection Changed事件中的以下代码解决了该问题:
///Identifies which Carousel Item is selected
CaroItem item = (CaroTest.SelectedItem as CaroItem);
tblTitle.Text = item.CItem.ToString();