Xamarin без заливки и расширения в шаблоне управления - PullRequest
0 голосов
/ 04 октября 2018

Я достиг определенного макета без использования шаблонов управления.Но когда я использую шаблон управления, макет ломается.Я не смог заполнить представление.

App.xaml

<Application.Resources>
    <ResourceDictionary>
        <Color x:Key="BaseColor">#2b3d51</Color>
        <Color x:Key="PrimaryColor">#5bb2f5</Color>
        <Color x:Key="SuccessColor">#5cd674</Color>
        <Color x:Key="WarningColor">#e7e75e</Color>
        <Color x:Key="DangerColor">#e87461</Color>
        <Color x:Key="EmptyColor">#f5f5f5</Color>
        <Color x:Key="NoFill">#fafafa</Color>
        <ControlTemplate x:Key="MainTemplate">
            <StackLayout Spacing="0">
                <StackLayout
                   Orientation="Horizontal"
                   VerticalOptions="Start"
                   HeightRequest="30"
                   BackgroundColor="{StaticResource BaseColor}">
                    <Label Text="&#xf009;"
                        FontSize="20"
                        TextColor="#fefefe"
                        VerticalOptions="Center"
                        HorizontalOptions="Center">
                        <Label.FontFamily>
                            <OnPlatform
                                x:TypeArguments="x:String"
                                Android="fontawesomesolid.otf#Font Awesome 5 Free Solid"
                                iOS="fontawesomesolid"/>
                        </Label.FontFamily>
                    </Label>
                </StackLayout>

                <StackLayout
                    Orientation="Horizontal"
                    VerticalOptions="FillAndExpand"
                    Spacing="0" BackgroundColor="Red">

                    <ContentPresenter></ContentPresenter>
                </StackLayout>

                <StackLayout
                   Orientation="Horizontal"
                   VerticalOptions="End"
                   HeightRequest="20"
                   BackgroundColor="Gray">

                </StackLayout>
            </StackLayout>

        </ControlTemplate>
    </ResourceDictionary>
</Application.Resources>

Page.xaml

<ContentPage.Content>
    <StackLayout
                    Orientation="Horizontal"
                    Spacing="0">
        <StackLayout
                        Orientation="Vertical"
                        BackgroundColor="Olive"
                        WidthRequest="130"
                           HorizontalOptions="Start"
                        >
            <Entry Placeholder="Search"></Entry>
            <Label Text="this is it"></Label>
            <Label Text="this is it"></Label>
            <Label Text="this is it"></Label>
        </StackLayout>

        <StackLayout
            Orientation="Vertical"
                       BackgroundColor="Silver"
                       HorizontalOptions="FillAndExpand"
                       >
            <StackLayout Orientation="Vertical" HeightRequest="100" BackgroundColor="Yellow">
                <Label Text="I'm here" ></Label>
            </StackLayout>
        </StackLayout>
    </StackLayout>

</ContentPage.Content>

Здесь вы можете видеть, что я использую боковую панельместа для контента Но контент не заполняет экран.enter image description here

из изображения выше вы можете видеть, что желтая и серебряная области должны заполнять оставшиеся пробелы красного цвета.Также я попробовал Grid layout, но тот же результат.Можете ли вы выяснить, что мне здесь не хватает?

1 Ответ

0 голосов
/ 04 октября 2018

Это было достигнуто с помощью сетки на родительских и дочерних страницах.

app.xaml

<Application.Resources>
    <ResourceDictionary>
        <ControlTemplate x:Key="MainTemplate">
            <Grid RowSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <StackLayout Grid.Row="0" Grid.Column="0" BackgroundColor="Navy"></StackLayout>
                <ContentPresenter Grid.Row="1" Grid.Column="0" BackgroundColor="Blue"></ContentPresenter>
                <StackLayout Grid.Row="2" Grid.Column="0" BackgroundColor="Brown"></StackLayout>
             </Grid>
        </ControlTemplate>
    </ResourceDictionary>
</Application.Resources> 

Page.xaml

<ContentPage.Content>
    <Grid ColumnSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="130" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <StackLayout Grid.Row="0" Grid.Column="0" BackgroundColor="DarkSeaGreen" Orientation="Vertical">
            <Entry Placeholder="Search"></Entry>
            <Label Text="this is it"></Label>
            <Label Text="this is it"></Label>
            <Label Text="this is it"></Label>
        </StackLayout>

        <StackLayout Grid.Row="0" Grid.Column="1" BackgroundColor="BurlyWood">
            <Label Text="I'm here"  BackgroundColor="AliceBlue"></Label>
        </StackLayout>
    </Grid>
</ContentPage.Content>

см. Скриншот enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...