Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

System.InvalidCastException: Specified cast is not valid.

$
0
0

I've been trying to solve this one for a few days. Thought I'd put it out here and see if anyone can help me see something...

The exception thrown

{System.InvalidCastException: Specified cast is not valid.
  at Xamarin.Forms.Grid+<>c.<.cctor>b__70_4 (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, Boolean fromStyle, Boolean checkAccess) [0x0005f] in <filename unknown>:0 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue (System.Object xamlelement, XmlName propertyName, System.Object value, Xamarin.Forms.BindableObject rootElement, INode node, Xamarin.Forms.Xaml.HydratationContext context, IXmlLineInfo lineInfo) [0x002c3] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, INode parentNode) [0x0005e] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ValueNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00089] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00054] in <filename unknown>:0 
  at Xamarin.Forms.Xaml.ApplyPropertiesVisitor+<>c__DisplayClass26_0.<SetDataTemplate>b__0 () [0x00094] in <filename unknown>:0 
  at Xamarin.Forms.DataTemplate.CreateContent () [0x00019] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].CreateContent (Int32 index, System.Object item, Boolean insert) [0x00021] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].GetOrCreateContent (Int32 index, System.Object item) [0x00023] in <filename unknown>:0 
  at Xamarin.Forms.TemplatedItemsList`2[TView,TItem].get_Item (Int32 index) [0x0000e] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCellForPath (Foundation.NSIndexPath indexPath) [0x00032] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:61 
  at Journyx.PCL.X3.iOS.Application.Main (System.String[] args) [0x000a0] in c:\Code\Journyx\Mobile\Mobile 3.0\trunk\Journyx.Mobile.X3\Journyx.Mobile.X3.iOS\Main.cs:49 }

This is the 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="Journyx.PCL.X3.View4.ViewProjectApprovalProjectUser"
             xmlns:controls="clr-namespace:Journyx.PCL.X3.Controls;assembly=Journyx.PCL.X3"
             xmlns:Template="clr-namespace:Journyx.PCL.X3.Template;assembly=Journyx.PCL.X3"
             xmlns:XLabs="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
             Icon="{x:Static Template:Resources.PageIcon}"
             BackgroundColor="{x:Static Template:Resources.PageBackgroundColor}">
  <StackLayout>
    <!-- Header-->
    <StackLayout VerticalOptions="StartAndExpand">
      <Grid x:Name="lvDaysGrid" Padding="0,4,0,4">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="3*" />
          <ColumnDefinition Width="7*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Text="Project:" Font="Small"/>
        <Label Grid.Row="0" Grid.Column="1" Text="{Binding Project}" Font="Bold, Small"/>
        <Label Grid.Row="1" Grid.Column="0" Text="User:" Font="Small"/>
        <Label Grid.Row="1" Grid.Column="1" Text="{Binding UserName}" Font="Bold, Small"/>
        <Label Grid.Row="2" Grid.Column="0" Text="Entry Type:" Font="Small"/>
        <Label Grid.Row="2" Grid.Column="1" Text="{Binding EntryType}" Font="Bold, Small"/>
        <Label Grid.Row="3" Grid.Column="0" Text="Amount:" Font="Small"/>
        <Label Grid.Row="3" Grid.Column="1" Text="{Binding Amount}" Font="Bold, Small"/>
        <Label Grid.Row="4" Grid.Column="0" Text="Period:" Font="Small"/>
        <Label Grid.Row="4" Grid.Column="1" Text="{Binding Period}" Font="Bold, Small"/>
      </Grid>
    </StackLayout>
    <!-- Grid -->
    <StackLayout Orientation="Vertical" >
      <ListView x:Name="lvDays"
        ItemsSource="{Binding Sheets}"
        HasUnevenRows="True">
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell Height="200">
              <ViewCell.View>
                <StackLayout Orientation="Vertical" >
                  <Grid x:Name="lvDaysGrid" Padding="0,4,0,4">
                    <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="3*" />
                      <ColumnDefinition Width="7*" />
                      <ColumnDefinition Width="80" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="Auto" />
                      <RowDefinition Height="auto" />
                      <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>
                    <!-- Row 1 -->
                    <Label Grid.Row="0" Grid.Column="0" Text="{Binding Day}" Font="Small"/>
                    <Label Grid.Row="0" Grid.Column="1" Text="{Binding Date}" Font="Bold, Small"/>
                    <Label Grid.Row="0" Grid.Column="2" Grid.RowSpacing="2" Text="{Binding Amount}" Font="Bold, Small"/>
                    <!-- Row 2 -->
                    <Label Grid.Row="1" Grid.Column="0" Text="{Binding CodeColumn}" IsVisible="{Binding CodeColumnVisible}" Font="Small"/>
                    <Label Grid.Row="1" Grid.Column="1" Text="{Binding Code}" IsVisible="{Binding CodeColumnVisible}" Font="Bold, Small"/>
                    <!-- Row 3 -->
                    <Label Grid.Row="2" Grid.Column="0" Text="{Binding SubCodeColumn}" IsVisible="{Binding SubCodeColumnVisible}" Font="Small"/>
                    <Label Grid.Row="2" Grid.Column="1" Text="{Binding SubCode}" IsVisible="{Binding SubCodeColumnVisible}" Font="Bold, Small"/>
                    <!-- Row 4 -->
                    <Label Grid.Row="3" Grid.Column="0" Text="{Binding SubSubCodeColumn}" IsVisible="{Binding SubSubCodeColumnVisible}" Font="Small"/>
                    <Label Grid.Row="3" Grid.Column="1" Text="{Binding SubSubCode}" IsVisible="{Binding SubSubCodeColumnVisible}" Font="Bold, Small"/>
                    <!-- Row 5 -->
                    <Button Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding Comment}" Command="{Binding CommandComment}" IsEnabled="{Binding CommentEnabled}" />
                    <!-- Row 6 -->
                    <Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding Attachments}" Command="{Binding CommandAttachment}" IsEnabled="{Binding AttachmentsEnabled}" />
                  </Grid>
                </StackLayout>
              </ViewCell.View>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
    </StackLayout>
    <StackLayout Orientation="Horizontal" Spacing="5" Padding="5" VerticalOptions="End">
      <Button Text="Approve" Command="{Binding CommandApprove}" HorizontalOptions="FillAndExpand"
        BackgroundColor="Green"
        TextColor="{x:Static Template:Resources.ButtonTextColor}"
        BorderRadius="{x:Static Template:Resources.ButtonBorderRadius}"/>
      <Button Text="Reject" Command="{Binding CommandReject}" HorizontalOptions="FillAndExpand"
        BackgroundColor="Red"
        TextColor="{x:Static Template:Resources.ButtonTextColor}"
        BorderRadius="{x:Static Template:Resources.ButtonBorderRadius}"/>
    </StackLayout>
  </StackLayout>
</ContentPage>

If I initialize ItemsSource="{Binding Sheets}" with an empty list, no problem. If I initialize it with data, all of which I have double and triple checked, as it all is either strings or bools, I get this invalid cast exception. I'm happy to post more code if anyone wants to see it...


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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