假设您有 2 个或更多共享相同结构的网格(行/列计数和属性相等)。
是否可以创建Style并设置RowDefinitions / ColumnDefinitions?
我已经试过了。但是当应用程序尝试解析 xaml 时出现此异常:
Xamarin.Forms.Xaml.XamlParseException:位置 14:9。属性值为 null 或不是 IEnumerable
我的源代码:
<StackLayout>
<StackLayout.Resources>
<ResourceDictionary>
<Style TargetType="Grid">
<Setter Property="RowDefinitions">
<Setter.Value>
<RowDefinition />
<RowDefinition />
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</StackLayout.Resources>
<Grid>
<Label Grid.Row="0" Text="(Grid #1) Row #1" />
<Label Grid.Row="1" Text="(Grid #1) Row #2" />
</Grid>
<Grid>
<Label Grid.Row="0" Text="(Grid #2) Row #1" />
<Label Grid.Row="1" Text="(Grid #2) Row #2" />
</Grid>
<Grid>
<Label Grid.Row="0" Text="(Grid #3) Row #1" />
<Label Grid.Row="1" Text="(Grid #3) Row #2" />
</Grid>
</StackLayout>
异常中的位置 14:9指的是第一个<RowDefinition />
标签。