我想在 Shell 视图中使用该模态中的按钮关闭模板 10 的模态。Shell.xaml.cs 中的关闭函数被触发,IsModal 和 HasError 被切换为 false,但模态对话框保持活动状态。
我使用的代码:
登陆页面视图模型:
public override async void OnNavigatedTo(object parameter, NavigationMode mode, IDictionary<string, object> state)
{
var i = await getMuscleScores();
if(i == null)
ShowError();
}
public void ShowError()
{
Views.Shell.SetError(true);
}
Shell.xaml.cs:
public bool IsModal { get; set; } = false;
public bool HasError { get; set; } = false;
public string ErrorText { get; set; } = "Something went wrong...";
public static void SetError(bool error, string text = null)
{
WindowWrapper.Current().Dispatcher.Dispatch(() =>
{
if (error)
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
else
BootStrapper.Current.UpdateShellBackButton();
Instance.IsModal = error;
Instance.IsBusy = !error;
Instance.HasError = error;
Instance.ErrorText = text == null ? "Something went wrong..." : text;
Instance.PropertyChanged?.Invoke(Instance, new PropertyChangedEventArgs(nameof(IsModal)));
Instance.PropertyChanged?.Invoke(Instance, new PropertyChangedEventArgs(nameof(HasError)));
Instance.PropertyChanged?.Invoke(Instance, new PropertyChangedEventArgs(nameof(ErrorText)));
});
}
public void HideError(object sender, TappedRoutedEventArgs e)
{
SetError(false);
}
Shell.xaml:
<Controls:ModalDialog.ModalContent>
<Grid>
<Viewbox Height="32">
<StackPanel Orientation="Horizontal" Visibility="{x:Bind IsBusy, Mode=OneWay, Converter={StaticResource visibilityConv}}">
<ProgressRing Width="16" Height="16"
Margin="12,0" Foreground="White"
IsActive="{x:Bind IsBusy, Mode=OneWay}" />
<TextBlock VerticalAlignment="Center" Foreground="White" Text="{x:Bind BusyText, Mode=OneWay}" />
</StackPanel>
</Viewbox>
<StackPanel Visibility="{x:Bind HasError, Mode=OneWay, Converter={StaticResource visibilityConv}}" VerticalAlignment="Center" Margin="12,0">
<TextBlock Text="Oops!" Style="{ThemeResource HeaderTextBlockStyle}"/>
<TextBlock Text="{x:Bind ErrorText, Mode=OneWay}"/>
<Button Content="Continue" Style="{StaticResource ButtonStyle}" HorizontalAlignment="Center" Tapped="HideError"/>
</StackPanel>
</Grid>
</Controls:ModalDialog.ModalContent>
我试图找到问题的另一件事是在LandingPageViewModel 中:
ShowError();
await Task.Delay(5000);
HideError();
这给了我与模态对话框保持打开状态相同的结果。因此,我认为使用不同的线程似乎出了点问题。有人知道这个问题的解决方案吗?顺便说一句:我正在使用最新版本的模板 10 在此处输入代码