Xamarin Forms ProgressBar未填充整个屏幕

kxkpmulp  于 7个月前  发布在  其他
关注(0)|答案(2)|浏览(81)

我正在给我的项目添加一个进度条,我想循环,但找不到一个好的。不管怎样,我添加了xamarin窗体原生进度条。它显示了一点,我想它填补从左到右和垂直中心红色。

<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
              
                <ProgressBar IsVisible="{Binding ProgressVisible}" HorizontalOptions="Fill"  VerticalOptions="CenterAndExpand" Progress="{Binding ProgressBarProgress}" x:Name="prgBar" ProgressColor="Aqua" />
               
            </StackLayout>

https://www.paste.tc/aktarimpagexaml这是我的整个页面代码。我该怎么解决这个问题?

hsvhsicv

hsvhsicv1#

您不需要在StackLayout中添加Orientation

<StackLayout>
      <ProgressBar  HorizontalOptions="Fill"  VerticalOptions="CenterAndExpand"  x:Name="prgBar" ProgressColor="Aqua" />
</StackLayout>
doinxwow

doinxwow2#

解决方案:

我这样更新了我的代码。我创建了一个新参数名称WidthReq并将其绑定到进度条WidthRequest="{Binding WidthReq}"。WidthReq被计算为适用于所有设备。

public double WidthReq { get => widthReq; set { widthReq = value; 
OnPropertyChanged(); } }
void getDeviceInfo()
    {

        // Get Metrics
        var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
        var width = mainDisplayInfo.Width;
        //HEIGHT
        var height = mainDisplayInfo.Height;
        // Screen density
        var density = mainDisplayInfo.Density;
        Console.WriteLine("DEVICE WIDTH : " + width + " DEVICE HEIGHT :"+ height + " DEVICE DENSITY : "+ density);

        var mywidthrequest = (width / density) * 0.9;
        WidthReq = mywidthrequest;

    }
    
     <StackLayout  >

                <ProgressBar  IsVisible="{Binding ProgressVisible}" WidthRequest="{Binding WidthReq}" HorizontalOptions="Fill"  VerticalOptions="CenterAndExpand" Progress="{Binding ProgressBarProgress}" x:Name="prgBar" ProgressColor="Aqua" />
               
            </StackLayout>

相关问题