添加listview隐藏表单背景图像Xamarin ios

时间:2017-09-30 07:48:22

标签: ios xamarin xamarin.forms

我正在开发Xamarin跨平台应用。 我有表单,我在构造函数上使用表单BackgroundImage = "timelinebackground.png";来设置背景图像。

它在精致的Android上工作但是当我在iOS中检查它时它没有显示背景图像。 当我从xaml中删除listview时,它的背景图像也会在iOS中显示。

这里是xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BMTHomesApp.Views.Timeline">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Logout" Order="Primary" Priority="0" Clicked="MenuItem_OnClicked"></ToolbarItem>
    </ContentPage.ToolbarItems>
    <StackLayout>
        <ListView
    x:Name="timelineListView"
            ItemTapped="timelineListView_ItemTapped"
    ItemsSource="{Binding .}"
    RowHeight="75"
    SeparatorVisibility="None">


        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid ColumnSpacing="0" RowSpacing="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="25" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                            <Label HorizontalOptions="Center" Text="{Binding ActualStartDate}" TextColor="#0073ae" />

                        <Label Grid.Column="2" Margin="20,0" FontSize="Medium" Text="{Binding StageName}" TextColor="#ffffff"/>

                        <!--<Label
              Grid.Row="1"
              Grid.Column="2"
              Margin="20,0"
              FontSize="Small"
              Text="Please add some desc text in api" TextColor="#ffffff"/>-->

                        <BoxView
                            Grid.RowSpan="2"
                            Grid.Column="1"
                            BackgroundColor="#ffffff"
                            HorizontalOptions="Center"
                            VerticalOptions="Fill"
                            WidthRequest="1" />

                        <Image Grid.Column="1" Source="Bullet.png" HeightRequest="25" WidthRequest="25" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

        <DatePicker x:Name="DatePickerTimeline" IsVisible="False"></DatePicker>
    </StackLayout>
</ContentPage>

和代码背后:

public partial class Timeline : ContentPage
    {
        public Timeline ()
        {
            InitializeComponent ();
            NavigationPage.SetBackButtonTitle(this, "");
            Title = "TIMELINE";
            BackgroundImage = "timelinebackground.png";


            var constructionStages = GetConstructionStages();
            if (!string.IsNullOrEmpty(constructionStages.Result.Error))
            {
                DisplayAlert("Error", constructionStages.Result.Error, "Ok");
            }
            else
            {
                timelineListView.ItemsSource = constructionStages.Result.ConstructionStages;
            }

        }

        private void timelineListView_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var selectedItem = (ConstructionStages) e.Item;

            if (!string.IsNullOrEmpty(selectedItem.ActualStartDate))
            {
                DateTime dateTimeStart;
                if (DateTime.TryParse(selectedItem.ActualStartDate, out dateTimeStart))
                {
                    DatePickerTimeline.MinimumDate = dateTimeStart;
                }
            }

            if (!string.IsNullOrEmpty(selectedItem.ActualCompletionDate))
            {
                DateTime dateTimeEnd;
                if (DateTime.TryParse(selectedItem.ActualCompletionDate, out dateTimeEnd))
                {
                    DatePickerTimeline.MaximumDate = dateTimeEnd;
                }
            }

            if (!string.IsNullOrEmpty(selectedItem.ActualStartDate) ||
                !string.IsNullOrEmpty(selectedItem.ActualCompletionDate))
            {
                DatePickerTimeline.Format = "MM-dd-yyyy";
                DatePickerTimeline.BackgroundColor = Color.FromHex("#ffffff");
                //DatePickerTimeline.IsVisible = true;
                DatePickerTimeline.Focus();
            }
            else
            {
                timelineListView.SelectedItem = null;
            }
        }

        private async Task<ConstructionStagesResponse> GetConstructionStages()
        {
            ConstructionStageManager manager = new ConstructionStageManager();
            var result = await manager.GetConstructionStages(Application.Current.Properties["SessionId"].ToString());
            return result;
        }

        private async void MenuItem_OnClicked(object sender, EventArgs e)
        {
            HelperClasses.LogOut();
            Application.Current.MainPage = new NavigationPage(new Login());
            //Navigation.PushAsync(new Login());
        }
    }

1 个答案:

答案 0 :(得分:1)

您需要将ListView的{​​{1}}媒体资源设置为透明,才能显示该网页的背景图片:

BackgroundColor