我在导航栏上有一个计时器,单击按钮后该计时器运行,该计时器在android上运行,但在iOS上我的计时器未更新。
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
if (cts.IsCancellationRequested)
{
return false;
}
else
{
Device.BeginInvokeOnMainThread(() =>
{
TimeSpan _TimeSpan = DateTime.Now - startAt;
ToolbarTimer.Text = _TimeSpan.ToString(@"hh\:mm\:ss");
});
return true;
}
});
对于自定义导航栏,您可以轻松使用TitleView(Shell或Naviagtion)
尝试这样的事情:
<Shell.TitleView>
<Grid VerticalOptions="Center"
HorizontalOptions="Center">
<StackLayout Orientation="Horizontal"
HorizontalOptions="Center">
<Label Text="{Binding Title}"
FontSize="20"
TextColor="White"
VerticalTextAlignment="Center"
HorizontalOptions="Center" />
<Label Text="{Binding Timer}"
FontSize="20"
TextColor="White"
VerticalTextAlignment="Center"
HorizontalOptions="Center" />
</StackLayout>
</Grid>
</Shell.TitleView>