如何更改xamarin上的htmllabel背景颜色宽度?

问题描述 投票:0回答:1

我想在xamarin中设置htmllabel文本背景颜色的宽度,但它覆盖了与文本长度一样长的颜色。我怎样才能覆盖整个背景?我希望红色区域与后面的绿松石色一样宽。

我正在从这样的服务发送 html 代码

Imd.DR = (d.OncelikID != (int)Sabitler.Oncelik.Yuksek) ? Fonksiyonlar.ModulDurumVer(d.DurumID ?? 0).Adi : "<span style=\"display:block; text-align:center; background-color:#ff0000; margin:auto; \">"
                                  + Fonksiyonlar.ModulDurumVer(d.DurumID ?? 0).Adi  + "<span>";

这是我在 xamarin 中的 xaml 代码:

<htmlLabel:HtmlLabel Text="{Binding DR}" BackgroundColor="#b2e8e7" TextColor="Black" FontSize="10" HorizontalTextAlignment="Center" LineBreakMode="NoWrap"  Style="{DynamicResource ListItemTextStyle}"   />

这是完整的xaml代码:

 <?xml version="1.0" encoding="utf-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="OzelKalem.Views.ListeContentViews.AramaListeContent"
             xmlns:htmlLabel="clr-namespace:LabelHtml.Forms.Plugin.Abstractions;assembly=OzelKalem"
                     xmlns:Prl="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"
               xmlns:local="clr-namespace:OzelKalem.Models"
             xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
             ios:Page.UseSafeArea="true"
             BackgroundColor="#00b3ae"
             NavigationPage.HasNavigationBar="false">
    <ContentView.Content>


        <Grid VerticalOptions="FillAndExpand" BackgroundColor="White" Margin="0" RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Row="0" Grid.Column="0" Margin="10">
                <StackLayout Orientation="Horizontal" >
                    <Button x:Name="Geri"  VerticalOptions="CenterAndExpand" HorizontalOptions="Center" Clicked="TarihDegistir" CommandParameter="-1" ContentLayout="Top,5" BackgroundColor="#edebeb"  BorderColor="#cccccc" BorderWidth="1" 
                        ImageSource="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.leftarrow.png }"  WidthRequest="30" HeightRequest="30" />
                    <Label Text="" x:Name="lbl_GosterimTurID" IsVisible="False"></Label>
                    <Label Text="" x:Name="lbl_VarsayilanTarih" IsVisible="False"></Label>
                    <StackLayout Orientation="Vertical" VerticalOptions="Center">
                        <Label Text="Saat" HorizontalOptions="Center" x:Name="lbl_Tarih" VerticalOptions="Center"  FontSize="10" HeightRequest="8" Margin="0" />
                        <Label Text="Saat" HorizontalOptions="Center" x:Name="lbl_GunTarih" VerticalOptions="Center"   FontSize="10" HeightRequest="8" Margin="0"/>
                    </StackLayout>
                    <Button x:Name="ileri" VerticalOptions="CenterAndExpand" HorizontalOptions="Center"   Clicked="TarihDegistir" CommandParameter="1" ContentLayout="Top,5"  BackgroundColor="#edebeb"  BorderColor="#cccccc" BorderWidth="1" 
                        ImageSource="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.rightarrow.png }"  WidthRequest="30" HeightRequest="30"  />
                </StackLayout>
            </Grid>
          
            <Grid Grid.Row="2"  RowSpacing="0" Margin="10,0,10,0" >

                <Prl:PullToRefreshLayout IsPullToRefreshEnabled="True" BackgroundColor="White" RefreshBackgroundColor="White"  x:Name="plr_Arama" VerticalOptions="FillAndExpand" >
                    <ScrollView>
                        <StackLayout  x:Name="stc_Arama" BindableLayout.ItemsSource="{Binding Icerik}" BackgroundColor="White" IsTabStop="True"   VerticalOptions="StartAndExpand">
                            <BindableLayout.ItemTemplate>
                                <DataTemplate>
                                    <StackLayout >
                                        <StackLayout.GestureRecognizers>
                                            <TapGestureRecognizer Tapped="arama_Secim"   />
                                        </StackLayout.GestureRecognizers>
                                        <Grid BackgroundColor="#0070c0" ColumnSpacing="1" RowSpacing="1" Padding="0,0,0,1" VerticalOptions="Start">
                                            <Grid BackgroundColor="White">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="{OnIdiom 
                                                Phone= {OnPlatform iOS=4*, Android=3*},
                                                Tablet= {OnPlatform iOS=2*, Android=2*}}">
                                                    </ColumnDefinition>
                                                    <ColumnDefinition Width="{OnIdiom 
                                                Phone= {OnPlatform iOS=6*, Android=5*},
                                                Tablet= {OnPlatform iOS=6*, Android=6*}}">
                                                    </ColumnDefinition>
                                                    <ColumnDefinition Width="{OnIdiom 
                                                Phone= {OnPlatform iOS=6*, Android=5*},
                                                Tablet= {OnPlatform iOS=6*, Android=6*}}">
                                                    </ColumnDefinition>
                                           
                                                </Grid.ColumnDefinitions>
                                                <Label Text="{Binding ID}" IsVisible="False" x:Name="ID" FontSize="10"  />

                                                <ContentView  Grid.Column="0">
                                                    <StackLayout >
                                            
                                                        <Label Text="{Binding GSaat}"  HorizontalTextAlignment="Center" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="10" />
                                                        
                                                        <ContentView BackgroundColor="#00b3ae" >
                                                            <ContentView BackgroundColor="White"  Margin="0,1,0,0" Padding="1">
                                                                <Label Text="{Binding DR}" BackgroundColor="#b2e8e7" TextColor="Black" FontSize="10" HorizontalTextAlignment="Center" LineBreakMode="NoWrap"  Style="{DynamicResource ListItemTextStyle}"   />
                                                            </ContentView>
                                                        </ContentView>
                                                        <Image Source="{local:ResourceResimExt ResourceId=OzelKalem.Content.images.modultalimat.png }" x:Name="img_Logo"   IsVisible="{Binding isTalimatSurecli,Converter={local:DegerKontrolkExtyeni}}" WidthRequest="15" HeightRequest="15"></Image>
                                                    </StackLayout>
                                                </ContentView>
                                                <StackLayout Grid.Column="1">
                                                    <!--<Label Text="{Binding KListe,Converter={local:KatilimciListeModel}}"  HorizontalOptions="Center" LineBreakMode="CharacterWrap" FontSize="12" />-->
                                                    <htmlLabel:HtmlLabel Text="{Binding KListe,Converter={local:KatilimciListeExt}}" FontSize="10" />
                                                    <Label Text="{Binding SListe,Converter={local:SurecListeExt}}" FontAttributes="Bold"   FontSize="8"  />
                                                </StackLayout>
                                                <StackLayout Grid.Column="2"  Orientation="Horizontal">
                                                    <htmlLabel:HtmlLabel Text="{Binding Ack}"    Style="{DynamicResource ListItemTextStyle}" FontSize="10"  HorizontalOptions="StartAndExpand" />
                                                    <!--<Label Text="{Binding Ack}"   Style="{DynamicResource ListItemTextStyle}" FontSize="10" HorizontalOptions="StartAndExpand" />-->

                                                    <Label Text="{Binding YKA}"  TextColor="Black" HorizontalOptions="End" VerticalOptions="Start" FontSize="10" FontAttributes="Bold"  IsVisible="{Binding YKA,Converter={local:DegerKontrolkExt}}" MinimumWidthRequest="40" />
                                                 
                                                       
                                                        <!--<Label Text="{Binding YKA}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="12" /-->
                                                
                                                </StackLayout>
                                               
                                           

                                        </Grid>
                                        </Grid>
                                    </StackLayout>
                                
                                </DataTemplate>
                            </BindableLayout.ItemTemplate>
                        </StackLayout>


                    </ScrollView>

                </Prl:PullToRefreshLayout>
    </Grid>
        </Grid>



    </ContentView.Content>
</ContentView>
html css xamarin label styles
1个回答
0
投票

通过将 HorizontalOptions 设置为

Fill
,将确保 View 填充其父布局的宽度。

您可以尝试以下方法:

HorizontalOptions="Fill"
© www.soinside.com 2019 - 2024. All rights reserved.