该页面包含:
我已经能够显示主要项目的图像,以及带有XAML的其他项目,如下所示:
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="450" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Main item -->
<StackLayout MinimumHeightRequest="450" HeightRequest="450">
<ffil:CachedImage Source="{Binding MainProduct.Icon}"
MinimumHeightRequest="450" HeightRequest="450"
Aspect="AspectFill"/>
</StackLayout>
<!-- Other items -->
<!-- through the use of 2 Repeaters -->
</Grid>
</ScrollView>
但是当我尝试添加主要素材图片上显示的内容时,我遇到了一个问题:页面不再显示导致应用在遇到错误时遇到错误页面是实例化的。
我添加了二级网格,它位于现有网格的第一行中,因为我希望shoud帮助我显示相关内容图像上的主要项目:
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="450" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Main item -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="**" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout MinimumHeightRequest="450" HeightRequest="450"
Grid.ColumnSpan="2" Grid.RowSpan="2">
<ffil:CachedImage Source="{Binding MainProduct.Icon}"
MinimumHeightRequest="450" HeightRequest="450"
Aspect="AspectFill"/>
</StackLayout>
<Frame BackgroundColor="Black"
Opacity="0.75"
Margin="10"
VerticalOptions="End" HorizontalOptions="End"
Grid.Column="1" Grid.Row="1">
<StackLayout>
<Label Text="{Binding MainProduct.Title}"
HorizontalOptions="StartAndExpand" VerticalTextAlignment="Center"/>
...
</StackLayout>
</Frame>
</Grid>
<!-- Other items -->
<!-- through the use of 2 Repeaters -->
</Grid>
</ScrollView>
我的XAML出了什么问题?有没有更好的方法通过RelativeLayout或AbsoluteLayout实现这一目标?
修改
错误如下:
{System.Reflection.TargetInvocationException:异常已经发生 由调用目标抛出。 ---&GT; System.FormatException: 其中一个标识的项目格式无效。在 Xamarin.Forms.GridLengthTypeConverter.ConvertFromInvariantString (System.String value)[0x000a0] in C:\ BuildAgent3 \工作\ ca3766cfc22354a1 \ Xamarin.Forms.Core \ GridLengthTypeConverter.cs:24 at MyProjectTablet.Views.ListProductPage.InitializeComponent() [0x00012] in C:\ Projets \ MyProject的\ MyProjectNewUi \ DevMyProjectNewUi \片剂\ MyProjectTablet \ MyProjectTablet \ OBJ \调试\ MyProjectTablet.Views.ListProductPage.xaml.g.cs:21 在MyProjectTablet.Views.ListProductPage..ctor()[0x00008]中 C:\ Projets \ MyProject的\ MyProjectNewUi \ DevMyProjectNewUi \平板\ MyProjectTablet \ MyProjectTablet \查看\ ListProductPage.xaml.cs:24 at(包装器托管到原生) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object [],System.Exception&amp;)at System.Reflection.MonoCMethod.InternalInvoke(System.Object obj, System.Object []参数)[0x00002] in &lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 ---内部异常结束 堆栈跟踪---在System.Reflection.MonoCMethod.InternalInvoke中 (System.Object obj,System.Object [] parameters)[0x00017] in &lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at System.RuntimeType.CreateInstanceMono(System.Boolean nonPublic) [0x000a8]在&lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at System.RuntimeType.CreateInstanceSlow(System.Boolean publicOnly, System.Boolean skipCheckThis,System.Boolean fillCache, System.Threading.StackCrawlMark&安培; stackMark)[0x00009] in &lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at System.RuntimeType.CreateInstanceDefaultCtor(System.Boolean publicOnly,System.Boolean skipCheckThis,System.Boolean fillCache, System.Threading.StackCrawlMark&安培; stackMark)[0x00027] in &lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at System.Activator.CreateInstance(System.Type类型,System.Boolean nonPublic)[0x0002c] in&lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at System.Activator.CreateInstance(System.Type type)[0x00000] in &lt; 657aa8fea4454dc898a9e5f379c58734&gt;:0 at MobileCommon.Services.NavigationService.CreatePage (MobileCommon.Services.PageType pageType,System.Object参数) [0x00053] in C:\ Projets \ MyProject的\ MyProjectNewUi \ DevMyProjectNewUi \移动\ MobileCommon \服务\ NavigationService.cs:118 }
我不明白为什么我会收到与GridLengthTypeConverter相关的异常......
答案 0 :(得分:0)
问题实际上是非常不同的 - 您在**
之一中意外使用了*
而不是ColumnDefinitions
:
<ColumnDefinition Width="**" />
通过查看异常堆栈跟踪来说明我是如何注意到的。您可以看到第二行显示Xamarin.Forms.GridLengthTypeConverter.ConvertFromInvariantString (System.String value)
。这很好地指出了错误的来源。
要获得n:1
列大小比例,您需要写n*
,其中n
是一个数字,而不是**
,如:
<ColumnDefinition Width="2*" />