xamarin - 自定义进度条未正确显示
问题描述
我用这个自定义的渲染器改变了我的进度条的高度:
public class CustomProgressBarRenderer : ProgressBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ProgressBar> e)
{
base.OnElementChanged(e);
Control.ProgressTintColor = Color.FromRgb(182, 231, 233).ToUIColor();// This changes the color of the progress
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
var X = 1.0f;
var Y = 10.0f; // This changes the height
CGAffineTransform transform = CGAffineTransform.MakeScale(X, Y);
Control.Transform = transform;
}
}
我在网格中使用我的自定义进度条。问题是,我看不到自定义进度条。看起来进度条位于另一个控件后面的页面顶部。因为如果我将进度条放在网格中 Margin="50" 的 StackLayout 中,则会出现进度条。然后看起来像
在 Android 应用程序中一切正常。此问题仅在IOS APP中出现。
有人知道如何将进度条居中吗?
谢谢
Xaml 代码
<customPages:CommonToolbarPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MC.Core.Views.Learn.Simple.LearnSimpleView"
xmlns:viewModelBase="clr-namespace:MC.Core.ViewModels.Base;assembly=MC.Core"
xmlns:customPages="clr-namespace:MC.Core.CustomPage;assembly=MC.Core"
xmlns:control="clr-namespace:MC.Core.Controls;assembly=MC.Core"
xmlns:translator="clr-namespace:MC.Core.Helpers"
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
Title="{Binding PageTitle}">
<ContentPage.ToolbarItems>
<ToolbarItem Command="{Binding RestartLearnCommand}" Text="{translator:Translate ButtonReset}" Priority="0" Order="Primary"></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<BoxView Grid.Row="0" HeightRequest="1" Style="{DynamicResource GreySeparatorLine}"></BoxView>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--Start ProgressBar Control-->
<ContentView Grid.Row="0" Grid.Column="0" Margin="10,0" >
<Grid Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Margin="1,0">
<Label Style="{DynamicResource RightVsWrongLabelStyle}" Text="{Binding CorrectVsWrongStatus}"></Label>
<Label Style="{DynamicResource LearnSystemLabelStyle}" Text="{translator:Translate LearnModusSimple}" ></Label>
</Grid>
<Grid Grid.Row="1" Grid.Column="0" Margin="1,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<StackLayout Margin="50">
<control:CustomProgressBar HeightRequest="10" x:Name="progressBar" Progress="{Binding LearnProgressValue}"></control:CustomProgressBar>
<Label Style="{DynamicResource ProgressBarLabelStyle}" Text="{Binding LabelProgressStatus}"></Label>
</StackLayout>
</Grid>
</Grid>
</Grid>
<ContentView.Triggers>
<DataTrigger TargetType="ContentView" Binding="{Binding ShowProgressBar}" Value="false">
<Setter Property="IsVisible" Value="false"></Setter>
</DataTrigger>
<DataTrigger TargetType="ContentView" Binding="{Binding ShowProgressBar}" Value="true">
<Setter Property="IsVisible" Value="true"></Setter>
</DataTrigger>
</ContentView.Triggers>
</ContentView>
<!--End ProgressBar Control-->
<!-- ... Some other code ... -->
</Grid>
</Grid>
</ContentPage.Content>
解决方案
推荐阅读
- javascript - Javascript 函数 - 无法读取未定义的属性“长度”
- jquery - jQuery 数据表的转换
- vb.net - 安装 VS 2017 更新后表单设计器缺少控件
- backup - 如何控制 Emacs 将备份文件动态生成到哪个目录?
- android - 如何在 Android 应用中查找权限来源?
- regex - 如何在 Google 电子表格中使用正则表达式来提取和删除原始文本?
- linux - 如何将 find 和 grep 的结果输出为 filename => found
- c++ - 如何让 CMake 使用 Mingw-w64 gcc/g++?
- tfs - 在 TFS 中构建时收到错误消息
- r - 尽管对我的数据使用了 scale_x_discrete,但 X 轴标签不存在