C# 刷新按钮UWP
我想在我的应用程序中添加一个刷新按钮,这样我就不必总是退出应用程序来清除数据 我尝试了一个C# 刷新按钮UWP,c#,xaml,uwp,refresh,C#,Xaml,Uwp,Refresh,我想在我的应用程序中添加一个刷新按钮,这样我就不必总是退出应用程序来清除数据 我尝试了一个刷新请求,但无法使其工作 C#code: private void RefreshButtonClick(object sender, RoutedEventArgs e) { RefreshContainer.requestRefresh(); } <RefreshContainer> <Grid HorizontalAlignment="Cent
刷新请求
,但无法使其工作
C#
code:
private void RefreshButtonClick(object sender, RoutedEventArgs e)
{
RefreshContainer.requestRefresh();
}
<RefreshContainer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" Click="Button_Click_Start" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" Click="Button_Click_Pause" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" Click="Button_Click_Reset" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" Click="Button_Click_Rest" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</RefreshContainer>
private void refreshButton单击(对象发送方,路由目标)
{
RefreshContainer.requestRefresh();
}
我希望应用程序数据刷新
刷新按钮UWP
我测试了您的代码,问题是您没有将可滚动控件设置为RefreshContainer的内容。基于@Stuart Smith提供的文档,您可以实现刷新功能,在此之前,您需要将上述网格内容放置在ScrollViewer
下
Xaml
<RefreshContainer Name="MyRefreshContainer" RefreshRequested="MyRefreshContainer_RefreshRequested">
<ScrollViewer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</ScrollViewer>
</RefreshContainer>
刷新按钮UWP
我测试了您的代码,问题是您没有将可滚动控件设置为RefreshContainer的内容。基于@Stuart Smith提供的文档,您可以实现刷新功能,在此之前,您需要将上述网格内容放置在ScrollViewer
下
Xaml
<RefreshContainer Name="MyRefreshContainer" RefreshRequested="MyRefreshContainer_RefreshRequested">
<ScrollViewer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</ScrollViewer>
</RefreshContainer>
Tomas,我看到你现在已经放弃了刷新按钮,但我想继续,以防你以后再访问这个按钮,或者其他人将来遇到这个问题 为了刷新数据,您需要对其进行编码。 “若要在需要时获取新内容,请处理RefreshRequested事件。在事件处理程序中,您需要特定于应用程序的代码来获取新内容。”。那里的文件里也有一个样本 您通常会为此使用数据绑定,RefreshRequested事件需要编辑绑定对象
using (var RefreshCompletionDeferral = args.GetDeferral())
{
await FetchAndInsertItemsAsync(3);
}
在该示例中,您会注意到FetchAndInsertItemsAsync正在向备份集合插入新项
这里有关于数据绑定的更多信息:Tomas,我看到您现在已经放弃了刷新按钮,但我想跟进一下,以防您以后再次访问此问题或其他人将来遇到此问题 为了刷新数据,您需要对其进行编码。 “若要在需要时获取新内容,请处理RefreshRequested事件。在事件处理程序中,您需要特定于应用程序的代码来获取新内容。”。那里的文件里也有一个样本 您通常会为此使用数据绑定,RefreshRequested事件需要编辑绑定对象
using (var RefreshCompletionDeferral = args.GetDeferral())
{
await FetchAndInsertItemsAsync(3);
}
在该示例中,您会注意到FetchAndInsertItemsAsync正在向备份集合插入新项
这里有关于数据绑定的更多信息:请查看MSDN中的以下示例。您需要设置数据绑定才能完成此工作,还需要一个数据模板。这也很复杂。另一种解决方案是设置数据绑定并刷新备份对象谢谢你的回答,我已经看到了拉入刷新的解决方案,但我正在寻找一个刷新按钮,你点击它,它会刷新你的页面。我尝试将pull to refresh调整为一个按钮,但无法查看MSDN中的以下示例。您需要设置数据绑定才能完成此工作,还需要一个数据模板。这也很复杂。另一种解决方案是设置数据绑定并刷新备份对象谢谢你的回答,我已经看到了拉入刷新的解决方案,但我正在寻找一个刷新按钮,你点击它,它会刷新你的页面。我试着调整拉刷新按钮,但没能改变太多!作为一个编程的绝对初学者,我不知道为了让刷新工作,应该使用什么等待方法。。你能再帮我一点忙吗?我用了这个:wait ApplicationData.Current.ClearAsync();但我得到了这个错误:System.IO。DirectoryNotFoundException@Tomas我测试了调用
wait ApplicationData.Current.ClearAsync()在MyRefreshContainer\u RefreshRequested
事件处理程序中,代码>运行良好。可以共享一个空白的复制示例吗?对于异步编程,请参考此。我尝试了您的解决方案,但当我按“刷新”时,什么也没有发生。我正在寻找一些真正可以刷新数据的东西,如果我不能刷新,甚至可以重新启动应用程序。谢谢,太多了!作为一个编程的绝对初学者,我不知道为了让刷新工作,应该使用什么等待方法。。你能再帮我一点忙吗?我用了这个:wait ApplicationData.Current.ClearAsync();但我得到了这个错误:System.IO。DirectoryNotFoundException@Tomas我测试了调用wait ApplicationData.Current.ClearAsync()在MyRefreshContainer\u RefreshRequested
事件处理程序中,代码>运行良好。可以共享一个空白的复制示例吗?对于异步编程,请参考此。我尝试了您的解决方案,但当我按“刷新”时,什么也没有发生。我正在寻找能够真正刷新数据的东西,如果我无法刷新,甚至可以重新启动应用程序