自定义进度栏未正确显示

时间:2018-11-26 22:10:01

标签: xamarin xamarin.forms xamarin.ios

我通过此自定义更改器更改了进度栏的高度:

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中,则会出现进度条。然后看起来像

enter image description here

在Android App中一切正常。这个问题只发生在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>

0 个答案:

没有答案