Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 91519 articles
Browse latest View live

Multiline text in a ListView (text cut off at the end)

$
0
0

I've see this topic a few times but right now when I need it, I can't find it... I have a problem with a few ListView's in my app. The ListViews are displaying content from a database and from a webservice. The content of the ListView can be very large and sometimes, the text is cut off...

This is my ListView so far:

<ListView Grid.Row="1" x:Name="DataListView" ItemsSource="{Binding GroupData}" GroupShortNameBinding="{Binding ShortCategory}" CachingStrategy="RecycleElement"
            IsGroupingEnabled="True" HasUnevenRows="True" BackgroundColor="#b99f65" SeparatorColor="#55492e" ItemTapped="ListView_OnItemTapped" Margin="0,3,0,0">
    <ListView.GroupHeaderTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid BackgroundColor="#120305" Margin="0">
                    <StackLayout Orientation="Horizontal" VerticalOptions="Center" Margin="15,0">
                        <Label Text="{Binding Category}" TextColor="#b99f65" FontSize="18" FontAttributes="Bold" />
                        <Label Text="{Binding ShortCategory, StringFormat='({0})'}" FontSize="18" TextColor="#b99f65" />
                    </StackLayout>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.GroupHeaderTemplate>

    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Vertical" Margin="10,5" VerticalOptions="Fill">
                    <Label Text="{Binding Name}" FontSize="14" FontAttributes="Bold" Margin="0" />

                    <Label Text="{Binding Effect}" FontSize="11" LineBreakMode="WordWrap" Margin="0" />
                    <Label Text="{Binding Ingredients, StringFormat='Ingredients: {0}'}" FontSize="11" LineBreakMode="WordWrap" Margin="0,3,0,0" SizeChanged="OnLabelSizeChanged" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Here, the Ingredients are cut off in iOS on some device sizes. I have implemented a SizeChanged-Event for the last Label to see if the size is set correctly, and it is. This is the output:

[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5
[0:] LABEL HEIGHT CHANGED:: 26.5
[0:] LABEL HEIGHT CHANGED:: 13.5

Any of the "26.5" height labels are cut off in half. Because this only happens on iOS it must be a problem there. Can someone help me out to fix this? I have the same issue on other places of my App too and haven't found a working solution yet... I know I can set the RowHeight to the max possible value but for this I need to know how many times the text will be wraped and it is not a nice solution... I would like to use the dynamic sizing...


How to Resolve Exception: Cannot create an instance of "WindowsPage".

$
0
0

Hey everyone,

Brand new to Xamarin forms here and trying to get started in cross platform app development using the package. However right out of the gate I seem to be running into an issue that has been asked a few times elsewhere but I haven't really seen an actual response on. Currently I'm trying to work on the UWP / Universal Windows / Windows 10 User Interface in a Portable Forms / PCL setup.

It's the Cannot create an instance of WindowsPage error message in the Microsoft Visual Studio 2015 Xaml designer. I'm following the guide at https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/ so I added the line for "xmlns:forms="using:Xamarin.Forms.Platform.UWP" the xaml file before changing the page tag from Page to forms:WindowsPage thus referencing the xamarin forms package. I did update all the NuGet packages to the latest version. Xamarin forms is something like 2.2 at the moment.

I initially installed the defaults for the VS2015 Xamarin package and I just tried modifying that installation with every extra component included so I don't think I'm missing anything there. I believe Xamarin is installed properly since it shows up in the Help -> Xamarin menu and I can choose new solutions out of the Xamarin forms package but I'm not sure what could be causing the issue.

Here's the XAML code

<forms:WindowsPage
    x:Class="SoloPathfinderPCL.UWP.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:forms="using:Xamarin.Forms.Platform.UWP"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SoloPathfinderPCL.UWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

</forms:WindowsPage>

Here's my Stack Trace for Exception: Cannot create an instance of "WindowsPage".
at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Type type, Boolean supportInternal) at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext context, ViewNode viewNode) at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode) at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode) at Microsoft.VisualStudio.DesignTools.WindowsXamlDesigner.InstanceBuilders.UserControlInstanceBuilder.Instantiate(IInstanceBuilderContext context, ViewNode viewNode) at Microsoft.VisualStudio.DesignTools.Platform.InstanceBuilders.ViewNodeManager.CreateInstance(IInstanceBuilder builder, ViewNode viewNode)

Hope someone can point me and everyone else having this issue in the right direction. Thanks.

2 Line Label with Tail Truncation

$
0
0

I'm converting a MonoTouch.Dialog app to Xamarin.Forms.

I have a Cell in a ListView and that has a "Detail" line that should be 2 lines long, and should truncate the tail after that.

        var lblDetail = new Label
        {
            LineBreakMode = LineBreakMode.TailTruncation,
            Text = "a really long string that should show 2 lines then ..."
        };

How do I set something like, "Lines = 2"

NavigationPage - Remove a page from the "back stack"

$
0
0

Hello everyone!

First of all i would like to say I am loving the new updates!

Ok, so I am working on an application that I do some processing during load of the application so I start on a Splash Screen. Once the processing is complete I take the user to one of two other Pages depending on the results of my processing. This works wonderfully.... except that I push the Splash Screen onto a NavigationPage in my GetMainPage function call as I want to use the Navigation page for the rest of the application. What this allows the user to do is hit their back button from the page I push them on to and it takes them back to the Splash Screen! I am in search of a way to make the navigation page essentially ignore the Splash Screen page. I thought of two ways this is possible but am not sure if either are possible...

  1. Don't use the NavigationPage in the GetMainPage call. Use some other Page type to display the Splash Screen. Once I am ready to move on switch to a NavigationPage then. I think this would be awesome except that I don't know if I can do it... is it possible to change to a NavigationPage after handing a different type on the GetMainPage function call?
  2. Have a function call to either erase the Navigation History or purge a specific page from the history. I did not see any way to do this unless I missed something...

Any help on keeping a page out of the navigation history would be greatly appreciated!

How to update content of a CarouselView

$
0
0

Hi,
I have a CarouselView were the content should shift depending on some user input. The CarouselView sets fine the first time but when I change the content of the ObservableCollection it dosn't effect the content of the CarouselView. I now when I did likely things with a listView I could cler the content and then add the bindable again but I don't see any options for that with CarouselView. Does someone know how to do this or can see what I'm doing wrong?

Function that refreshes the content:

        void setShowMore() {
            this.Images = new ObservableCollection<Img>();
            if (choosenEO.subPages[showMoreCounter].imgs.Count > 0)
            {
                for (var i = 0; i< choosenEO.subPages[showMoreCounter].imgs.Count; i++)
                {
                    this.Images.Add(new Img() { src = choosenEO.subPages[showMoreCounter].imgs[i].src });
                }
            }
            System.Diagnostics.Debug.WriteLine("Length of Images:" + this.Images.Count);
                this.BindingContext = this;
        }

And in xaml:

                    <cv:CarouselView x:Name="caroView" ItemsSource="{Binding Images}" BackgroundColor="Lime" HeightRequest="200" WidthRequest="200">
                        <cv:CarouselView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Red">
                                    <Label Text="{Binding src}"/>
                                    <Image Aspect="AspectFill" Source="{Binding src}" />
                                </StackLayout>
                            </DataTemplate>
                        </cv:CarouselView.ItemTemplate>
                    </cv:CarouselView>

Best regards
/magnus

Anyone else having issues with ObservableCollection not updating the Listview

$
0
0
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class=".Views.MainPageView"
             Title="" Icon="menu_icon.png">
  <MasterDetailPage.Detail>
    <ContentPage Title="title" >
      <Grid RowSpacing="0" >
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="50" />
          <RowDefinition Height="50" />
          <RowDefinition Height="20" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Text="{Binding ErrorText}" Grid.Row="2" Grid.ColumnSpan="2" Grid.Column="0" TextColor="Red" FontSize="8" LineBreakMode="WordWrap"/>
        <ListView ItemsSource="{Binding Grouped}" Grid.Row="3" Grid.ColumnSpan="2"
                  Grid.Column="0" IsGroupingEnabled="True" GroupDisplayBinding="{Binding Key}" HasUnevenRows="True"
                  GroupShortNameBinding="{Binding Key}" IsPullToRefreshEnabled="True" RefreshCommand="{Binding RefreshCommand}"
                  IsRefreshing="{Binding IsBusy, Mode=OneWay}">
          <ListView.GroupHeaderTemplate>
            <DataTemplate>
              <ViewCell Height="25">
                <StackLayout VerticalOptions="FillAndExpand" Padding="5">
                  <Label Text="{Binding Key}" TextColor="White" VerticalOptions="Center" />
                </StackLayout>
              </ViewCell>
            </DataTemplate>
          </ListView.GroupHeaderTemplate>
          <ListView.ItemTemplate>
            <DataTemplate>
              <ViewCell>
                <Grid RowSpacing="0" Padding="5">
                  <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="3*" />
                    <ColumnDefinition Width="*" />
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="*" />
                  </Grid.RowDefinitions>
                  <Label Text="{Binding name}" FontSize="12" FontAttributes="Bold" Grid.Row="0" Grid.Column="0" />
                  <Label Text="{Binding date, StringFormat='{}{0:dd-MM-yyyy}'}" Grid.Row="0" FontSize="10" Grid.Column="1" />
                </Grid>
              </ViewCell>
            </DataTemplate>
          </ListView.ItemTemplate>
        </ListView>
      </Grid>
    </ContentPage>
  </MasterDetailPage.Detail>
</MasterDetailPage>



namespace.ViewModel
{
    public class MainViewModel : ViewModelBase, INotifyPropertyChanged
    {
        private readonly INavigationService _navigationService

        public MainViewModel(INavigationService navigationservice)
        {

            Messenger.Default.Register<RefreshMessage>(this, msg => RefreshData());
            _navigationService = navigationservice;
        }

        private async void RefreshData()
        {


                ClientReturn response = await client.GetClients();

                            Clients = new ObservableCollection<Client>(response.Clients);

                            var sorted = from singleclient in Clients
                                         orderby singleclient.ClientName
                                         group singleclient by singleclient.NameSort into clientGroup
                                         select new Grouping<string, Client>(clientGroup.Key, clientGroup);

                         Grouped = new ObservableCollection<Grouping<string, Client>>(sorted);

        }





        private RelayCommand _refreshCommand;
        public RelayCommand RefreshCommand
        {
            get
            {
                return _refreshCommand ?? (_refreshCommand = new RelayCommand(() => { RefreshData(); }));
            }
        }

        public ObservableCollection<Client> Clients { get; set; }

        public ObservableCollection<Grouping<string, Client>> ClientsGrouped { get; set; }



        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
            }
        }
    }
}

The problem is my normal bindings are updated, hoever the listview isn't updated at all, while the ClientsGrouped is indeed updated upon object inspection.

I've also updated it with the VM now, however please note that I only posted the relevant information. Things like error handling and else have been omitted.

Is it possible to have different colors for toolbar item and title?

$
0
0

At the moment I set the color for the toolbar in App.xaml.cs

 MainPage = new NavigationPage(new TSPage())
 {
    BarBackgroundColor = Color.White,
        BarTextColor = Color.Black
};

The problem is that the text for the toolbar and the title of the page will use the same color, but I would like to have different color for the item. Is it possible? Actually I need this for iOS and Android.

Remote iOS Simulator Audio does not working

$
0
0

I build app with xamarin forms, where I reproduce a < audio > streaming embebed in a webview, So, in Android works perfect but not in iOS. NO device NOR simulator.

remote ios simulator sounds does not working. Somebody has the same problem? How can I fix this?

I configure ATS, for all, for eaach domain. but nothing happens.

Actually it's in production and you can see in stores and codes. hope you can help

https://github.com/esurmay/App1/blob/development/App1/App1/Views/RadioVivoPage.xaml.cs


Audio in WebView on iOS?

$
0
0

Hi,

Im opening a website that play an audio file in a webview. There is no sound on my real device? But on the simulator it works fine.
Any suggestions or ideas what it could be?

Thanks in advance!
best regards Ali

Custom template in Telerik calendar cell

Cast visual objects with derived View Class

$
0
0

Hello Community,

I have a quick question.
I'm trying to cast a derived class to cast visual objects.

I've created classes for some visual objects that should take care of the look. This is the reason for creating CLabel, CButton and CEntry classes. I derive the classes from Label, Button and Entry.
Additionally I created a class: class Control: View

In the later part of my code I have an object called oControl. oControl can be any visual element, like CLabel, CEntry, CButton.
What I want to do is, to cast the Elements over the Control Class and then i want to add the Elements to a List.
Here's what I'll do.
mylist.Add((Control)oControl)
The problem is, this command returns the error: Specified cast is not valid.
If I do it like this: mylist.Add((View)oControl), it works without problems.
Is there a way to cast the visual objects over Conrol? My research has shown that it should not work with the way I want to do it.
Is there still a way?

Best regards
fdogan

Making WebView play audio in background

$
0
0

Hello people!
I have a very simple Xamarin.Forms project which is basically a xaml with a webview. This webview opens a website where the user can select and listen to music.
It's working on all platforms, but I need the webview to continue to play audio, even if the application is minimized or the phone screen is blocked.
I've been frozen in it for 4 days and have no idea how to do it =(
Could someone help me or give me some direction?

The "XamlCTask" task failed unexpectedly.

$
0
0

Hello Team,
I am facing this The "XamlCTask" task failed unexpectedly. problem after adding the xamarin.forms.maps package to my application.

Waiting for your response.

WebView Source property binding to parent control's ItemsSource

$
0
0

I have a created a custom StackLayout where an ItemTemplate can be defined as well as an ItemsSource. I already used it multiple times in the past and I believe it works. I tried to make the ItemTemplate be a WebView that takes its' Source property value from an ObservableCollection of URL's by using Binding. The code:

<ContentPage.Content> <ScrollView> <custom:RepeatingStackLayout ItemsSource="{Binding ArticlesCollection}" Margin="5"> <custom:RepeatingStackLayout.ItemTemplate> <DataTemplate> <WebView Source="{Binding UrlAddress}" /> </DataTemplate> </custom:RepeatingStackLayout.ItemTemplate> </custom:RepeatingStackLayout> </ScrollView> </ContentPage.Content>

In the debug output I can see it's trying to contact the website as well as JavaScript files associated with it and more, however evantually, the website doesn't load and in the debug output it shows what I believe to be an error message:

[INFO:CONSOLE(1)] "Uncaught TypeError: e.data.indexOf is not a function", source: http://mobile.mako.co.il/news-israel/health/Article-f4cffa993c61c31004.htm (1)

09-07 08:22:40.185 I/chromium( 3112): [INFO:CONSOLE(1)] "Uncaught TypeError: e.data.indexOf is not a function", source: http://mobile.mako.co.il/news-israel/health/Article-f4cffa993c61c31004.htm (1)

I do want to point out that the website is online for sure, and also, when I created a page with just a WebView and set its' source to that website, it did work. Please help!

Could not load assembly Microsoft.Threading.Tasks

$
0
0

Hey,

I am receiving the following error on iOS and Android project. Anybody has any workaround for this issue? This post recommends a workaround but the steps are vague.

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'Microsoft.Threading.Tasks.dll' at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.Execute() (Braemar.Vers.Mobile.Droid)

I think that these two paths should have this file but I couldn't find it.
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v1.0

Xamarin Studio:
Version 5.10.2 (build 56)
Installation UUID: 88f72eda-5030-43e9-8d1b-7658e8a17627

Runtime:
Microsoft .NET 4.0.30319.42000
GTK+ 2.24.23 (MS-Windows theme)
GTK# 2.12.30

Xamarin.Android:
Version: 6.0.1.10 (Business Edition)
Android SDK: C:\Android\android-sdk
Supported Android versions:
2.3 (API level 10)
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
4.4.87 (API level 20)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.1.0 rc1
SDK Build Tools Version: 23.0.2

Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

Build Information:
Release ID: 510020056
Git revision: bb74ff467c62ded42b7b7ac7fdd2edc60f8647b0
Build date: 2016-01-26 15:49:39-05
Xamarin addins: 8b797d7ba24d5abab226c2cf9fda77f666263f1b
Build lane: monodevelop-windows-cycle6-c6sr1

Operating System:
Windows 10.0.10586.0 (64-bit)

Project Information:
PCL 4.5 - Profile 7


Load an assembly at runtime

$
0
0

Hello guys,

i got a little problem with my Xamarin.Forms Application.
I'll try to implement an on the fly updater, wich downloads some DLLs from a Webservice an loads it.
It works fine with the Shared piece of code., but when it comes to a dll wich contains Android specific stuff then it does not work perfectly.

For example: I have to register Dependency manually in a method wich I call when the DLL get loaded.
Sadly it doesnt work with CostumRenderer. Xamarin just dont recognize that I want to register an Costumrenderer... Do anyone have an idea how to fix this Problem or does someone got a smart workaround?

How to add a gestureListener to a label in an item template

$
0
0

Hi all,

I have a carousel page, and i am using the item template.
On a normal content page i could add the gesture listener, without any problems, however i do not seem to be able to add it to the item template. Does anyone know how this could be done, and if it can be done?

Update xamarin forms and maps regression

$
0
0

Hello all,

I've been occupied on other things this summer and wanted to update all my project's packages. Everything's fine, building and so ...

But I've got a probleme on the map. I was using the showing user option on the map to allow the user to find himself like on GoogleMap (the button on top right to go there) but it disappeared and I can't figure out why.

Notice that I'm using package TK.CustomMap for my project but which extends Xamarin Forms Maps and I got the prob since I updated Xamarin.Forms.Maps package

Did someone met the same problem after updating to last version of Xamarin.Forms.Maps ?

<package id="Xamarin.Forms" version="2.3.4.224" targetFramework="portable45-net45+win8+wp8+wpa81" />
  <package id="Xamarin.Forms.Maps" version="2.3.3.193" targetFramework="portable45-net45+win8+wp8+wpa81" />

TO

<package id="Xamarin.Forms" version="2.3.4.270" targetFramework="portable45-net45+win8+wp8+wpa81" />
  <package id="Xamarin.Forms.Maps" version="2.3.4.270" targetFramework="portable45-net45+win8+wp8+wpa81" />

Thanks

Xamarin.Forms.Maps no zoom control on iOS

$
0
0

Android and UWP have working zoom, but not iOS. I tried setting HasZoomEnabled to true, but that didn't help. Is this something that needs help in my renderer?

Lines and columns in my grid are broken

$
0
0

Look the image below

and below my code in c#
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPageItens : ContentPage
{
ObservableCollection _data { get; set; }
public int IdOrcamento { get; set; }
public MainPageItens()
{
InitializeComponent();
}

        public MainPageItens(int idorcamento)
        {
            InitializeComponent();

            this.IdOrcamento = idorcamento;
            _data = new ObservableCollection<ItensLib>();

            // Crete a grid for "title"
            Grid grid = CreateGrid();
            grid.Children.Add(new Label { Text = "Produto", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 0, 1, 0, 1);
            grid.Children.Add(SeparatorV(), 1, 2, 0, 1);
            grid.Children.Add(new Label { Text = "Qtde", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 2, 3, 0, 1);
            grid.Children.Add(SeparatorV(), 3, 4, 0, 1);
            grid.Children.Add(new Label { Text = "Unitário", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 4, 5, 0, 1);
            grid.Children.Add(SeparatorV(), 5, 6, 0, 1);
            grid.Children.Add(new Label { Text = "Custo", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 6, 7, 0, 1);
            grid.Children.Add(SeparatorV(), 7, 8, 0, 1);
            grid.Children.Add(new Label { Text = "Custo Dia", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 8, 9, 0, 1);
            grid.Children.Add(SeparatorV(), 9, 10, 0, 1);
            grid.Children.Add(new Label { Text = "Ult. Vencto", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 10, 11, 0, 1);
            grid.Children.Add(SeparatorV(), 11, 12, 0, 1);
            grid.Children.Add(new Label { Text = "Total", TextColor = Color.Red, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center }, 12, 13, 0, 1);
            grid.Children.Add(SeparatorV(), 13, 14, 0, 1);

            grid.Children.Add(SeparatorH(), 0, 5, 1, 2);

            // Create the ListView to visualize my data
            ListView lv = new ListView() { HasUnevenRows = true, SeparatorVisibility = SeparatorVisibility.None };
            lv.ItemsSource = _data;
            lv.ItemTemplate = new DataTemplate(typeof(ListViewTemplateGrid));

            StackLayout sl = new StackLayout() { Children = { grid, lv }, Spacing = 0 };

            this.Content = sl;
        }

        static Grid CreateGrid()
        {

            Grid grid = new Grid() { RowSpacing = 0, ColumnSpacing = 0 };

            // Define row
            RowDefinition rd = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) };
            RowDefinition rdSeparator = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) };

            // Define columns (one for every property I have to visualize)
            ColumnDefinition cdProduto = new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Star) };
            ColumnDefinition cdQtde = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
            ColumnDefinition cdUnitario = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
            ColumnDefinition cdCusto = new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Star) };
            ColumnDefinition cdCustoDia = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
            ColumnDefinition cdUltVencto = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
            ColumnDefinition cdTotal = new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Star) };

            // Add row and columns to grid
            grid.RowDefinitions.Add(rd);
            grid.RowDefinitions.Add(rdSeparator);

            grid.ColumnDefinitions.Add(cdProduto);
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Absolute) }); // Separator
            grid.ColumnDefinitions.Add(cdQtde);
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Absolute) }); // Separator
            grid.ColumnDefinitions.Add(cdUnitario);
            grid.ColumnDefinitions.Add(cdCusto);
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Absolute) }); // Separator
            grid.ColumnDefinitions.Add(cdCustoDia);
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Absolute) }); // Separator
            grid.ColumnDefinitions.Add(cdUltVencto);
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(2, GridUnitType.Absolute) }); // Separator
            grid.ColumnDefinitions.Add(cdTotal);

            return grid;
        }

        static BoxView SeparatorV()
        {

            return new BoxView() { WidthRequest = 2, BackgroundColor = Color.Red };
        }

        static BoxView SeparatorH()
        {

            return new BoxView() { HeightRequest = 2, BackgroundColor = Color.Red };
        }

        class ListViewTemplateGrid : ViewCell
        {
            public ListViewTemplateGrid()
            {


                Label labelProduto = new Label() { VerticalOptions = LayoutOptions.Center };
                labelProduto.SetBinding(Label.TextProperty, "Produto");

                Label labelQtde = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                labelQtde.SetBinding(Label.TextProperty, "Qtde");

                Label labelUnitario = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                labelUnitario.SetBinding(Label.TextProperty, "Unitario");

                Label labelCusto = new Label() { VerticalOptions = LayoutOptions.Center };
                labelCusto.SetBinding(Label.TextProperty, "Custo");

                Label labelCustoDia = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                labelCustoDia.SetBinding(Label.TextProperty, "Custo Diario");

                Label labelUltVencto = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                labelUltVencto.SetBinding(Label.TextProperty, "Ult. Vencto");

                Label labelTotal = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                labelTotal.SetBinding(Label.TextProperty, "UTotal");

                // Add controls to the grid
                Grid grid = CreateGrid();
                grid.Children.Add(labelProduto, 0, 1, 0, 1);
                grid.Children.Add(SeparatorV(), 1, 2, 0, 1);
                grid.Children.Add(labelQtde, 2, 3, 0, 1);
                grid.Children.Add(SeparatorV(), 3, 4, 0, 1);
                grid.Children.Add(labelUnitario, 4, 5, 0, 1);
                grid.Children.Add(SeparatorV(), 5, 6, 0, 1);
                grid.Children.Add(labelCusto, 6, 7, 0, 1);
                grid.Children.Add(SeparatorV(), 7, 8, 0, 1);
                grid.Children.Add(labelCustoDia, 8, 9, 0, 1);
                grid.Children.Add(SeparatorV(), 9, 10, 0, 1);
                grid.Children.Add(labelUltVencto, 10, 11, 0, 1);
                grid.Children.Add(SeparatorV(), 11, 12, 0, 1);
                grid.Children.Add(labelTotal, 12, 13, 0, 1);

                grid.Children.Add(SeparatorH(), 0, 5, 1, 2);

                this.View = grid;

            }
        }

        private async void btnVoltar_Clicked(object sender, EventArgs e)
        {
            await Navigation.PopModalAsync(true);
        }

        private async void btnOk_Clicked(object sender, EventArgs e)
        {
            //
        }
    }

This Attribute I don't put on my code
[XamlCompilation(XamlCompilationOptions.Compile)]

How can I solve this issue? I need to large my grid, so need to create a horizontal and vertical scroll.

Viewing all 91519 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>