繁体   English   中英

SelectionChanged和一个FlipView

[英]SelectionChanged and a FlipView

我正在使用Windows通用应用程序,我有一个包含2页的FlipView,每个页面包含4个按钮,我想当我从page1滚动时得到page2,我这样尝试过:

<Page.Resources>
<DataTemplate x:Key="FlipViewItemTemplate">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" />
<Button Grid.Column="0" Grid.Row="1" />
<Button Grid.Column="1" Grid.Row="0" />
<Button Grid.Column="1" Grid.Row="1" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="FlipViewItemTemplate1">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Column="0" Grid.Row="0" />
<Button Grid.Column="0" Grid.Row="1" />
<Button Grid.Column="1" Grid.Row="0" />
<Button Grid.Column="1" Grid.Row="1" />
</Grid>
</DataTemplate>
</Page.Resources

我从名为flipView1的flipView中调用了此方法:

private void flipView1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
  {
   flipView1.ItemTemplate = Resources["FlipViewItemTemplate"] as DataTemplate;
   }

我得到的是一页带有4个按钮的页面,没有滚动,是否可以使用任何方法在滚动中显示不同的页面

感谢帮助

DataTemplateSelector

可能是使用DataTemplateSelector的解决方案

这是一个示例:1)该类必须继承自DataTemplateSelector nanamespace ExploringOfficeRestAPI.Styles.DataTemplateSelectors {public class FileFolderDataTemplateSelector:DataTemplateSelector {public DataTemplate FileTemplate {get; 组; } public DataTemplate FolderTemplate { 组; }
受保护的重写DataTemplate SelectTemplateCore(对象项,DependencyObject容器){var viewModelPublic = item作为OneDrivePublicFile; 如果(viewModelPublic!= null){如果(viewModelPublic.IsFile()){返回FileTemplate; }

            return FolderTemplate;
        }          
        return FolderTemplate;

    }
}

} 2)定义您的XAML DataTemplate:Grid.Row =“ 0” Grid.RowSpan =“ 2” Margin =“ 0” VerticalAlignment =“ Stretch” Height =“ 150” Width =“ 150”
SelectionHighlightColor =“ {StaticResource EORAForegroundBrush}” /> Grid.Row =“ 0” Margin =“ 0,0,10,0” VerticalAlignment =“ Top” Horizo​​ntalAlignment =“ Right” /> Grid.Row =“ 1” Margin =“ 10,0,0,-20“ VerticalAlignment =” Bottom“ />

    </Grid>

</DataTemplate>
<DataTemplate x:Key="FileTemplate">
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>

        <Image Source="{Binding ThumbnailUrl}" Width="150" Height="150" Margin="0,0,0,0" Grid.RowSpan="2" VerticalAlignment="Top" />
        <TextBlock Text="{Binding name}" Foreground="{StaticResource EORAForegroundBrush}" 
                         Style="{StaticResource EORATextBlockStyle}" Width="auto" Height="50"  
                          Grid.Row="1" Margin="10,0,0,-20" VerticalAlignment="Bottom"  HorizontalAlignment="Left" />

    </Grid>
</DataTemplate>

3)在XAMl中定义选择器:xmlns:selector =“ using:ExploringOfficeRestAPI.Styles.DataTemplateSelectors”

        <selector:FileFolderDataTemplateSelector 
                    x:Key="FileFolderDataTemplateSelector" 
                    FolderTemplate="{StaticResource FolderTemplate}"
                    FileTemplate="{StaticResource FileTemplate}"/>

4)最后为FlipView定义ItemTemplateSelector =“ {StaticResource FileFolderDataTemplateSelector}”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM