[英]How can I simulate a ViewCell in a TableSection with a Grid inside a StackLayout?
我的應用程序調用了兩個模板,這些模板創建類似於兩個ViewCell的東西:
<StackLayout Orientation="Horizontal" Padding="10">
<template:DataGridTemplate Text="Updated" Label="{Binding Updated}" />
<template:DataGridTemplate Text="Version" Label="{Binding Version}" />
</StackLayout>
這是模板XAML
<?xml version="1.0" encoding="utf-8"?>
<Grid Padding="20,0" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Japanese;assembly=Japanese"
x:Class="Japanese.Templates.DataGridTemplate"
x:Name="this">
<local:StyledLabel Text="{Binding Text, Source={x:Reference this}}" HorizontalOptions="Start" VerticalTextAlignment="Center" />
<local:StyledLabel Text="{Binding Label, Source={x:Reference this}}" HorizontalOptions="End" VerticalTextAlignment="Center" />
</Grid>
我希望模板的高度為50,並且希望在兩個模板之間創建一條線,以模擬在TableSection內的ViewCell中可以找到的東西。
有人對我該如何做有什么建議嗎? 我嘗試將Grid的高度設置為50,但這告訴我這是一個只讀屬性。
StackLayout
<StackLayout Orientation="Vertical" Padding="10" Spacing="0">
<template:DataGridTemplate Text="Updated" Label="07/21/2018" />
<template:DataGridTemplate Text="Version" Label="1.0.0" />
</StackLayout>
DataGridTemplate (行分隔符在此處,但可以直接添加到StackLayout中)
<?xml version="1.0" encoding="utf-8"?>
<Grid Padding="20,0" HeightRequest="50" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Sof2"
x:Class="Sof2.Templates.DataGridTemplate"
x:Name="this">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<local:StyledLabel Grid.Column="0" Text="{Binding Text, Source={x:Reference this}}" VerticalTextAlignment="Center" />
<local:StyledLabel Grid.Column="1" Text="{Binding Label, Source={x:Reference this}}" TextColor="Silver" VerticalTextAlignment="Center" />
<!-- Separator -->
<BoxView Grid.ColumnSpan="2" BackgroundColor="Silver" HeightRequest="1" VerticalOptions="End" />
</Grid>
結果
如果需要交互性,則可以適當添加TapGestureRecognizers。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.