una sola poner pies pie pagina modelos mas insertar hoja hacer grande encabezado como xamarin xamarin.forms

xamarin - sola - modelos de pie de pagina en word



¿Cómo puedo configurar diferentes pies de página para TableSections cuando uso un Renderizador TableView personalizado? (2)

Estoy usando un procesador para permitirme establecer un pie de página personalizado en mi TableView. El renderizador funciona, pero me gustaría tener la capacidad de configurar diferentes pies de página para las diferentes secciones de la tabla. Por ejemplo, un pie de página para la sección de la tabla 0 y otro para la sección de la tabla 1, todo el camino hasta la sección de la tabla 5.

Aquí está el XAML que estoy usando:

<!-- <local:ExtFooterTableView x:Name="tableView" Intent="Settings" HasUnevenRows="True">--> <TableView x:Name="tableView" Intent="Settings" HasUnevenRows="True"> <TableSection Title="Cards1"> <ViewCell Height="50"> <Label Text="Hello1" /> </ViewCell> <ViewCell Height="50"> <Label Text="Hello2" /> </ViewCell> </TableSection> <TableSection Title="Cards2"> <TextCell Height="50" Text="Hello"></TextCell> </TableSection> </TableSection> <!-- </local:ExtFooterTableView>--> </TableView>

y aquí está la clase C # y el renderizador:

public class ExtFooterTableView : TableView { public ExtFooterTableView() { } }

y:

using System; using Japanese; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; [assembly: ExportRenderer(typeof(ExtFooterTableView), typeof(Japanese.iOS.ExtFooterTableViewRenderer))] namespace Japanese.iOS { public class ExtFooterTableViewRenderer : TableViewRenderer { protected override void OnElementChanged(ElementChangedEventArgs<TableView> e) { base.OnElementChanged(e); if (Control == null) return; var tableView = Control as UITableView; var formsTableView = Element as TableView; tableView.WeakDelegate = new CustomFooterTableViewModelRenderer(formsTableView); } private class CustomFooterTableViewModelRenderer : TableViewModelRenderer { public CustomFooterTableViewModelRenderer(TableView model) : base(model) { } public override UIView GetViewForFooter(UITableView tableView, nint section) { Debug.WriteLine("xx"); if (section == 0) { return new UILabel() { // Text = TitleForFooter(tableView, section), // or use some other text here Text = "abc", TextAlignment = UITextAlignment.Left // TextAlignment = NSTextAlignment.NSTextAlignmentJustified }; } else { return new UILabel() { // Text = TitleForFooter(tableView, section), // or use some other text here Text = "def", TextAlignment = UITextAlignment.Left // TextAlignment = NSTextAlignment.NSTextAlignmentJustified }; } } } } }

El código funciona pero me gustaría saber cómo puedo configurar un texto de pie de página diferente para diferentes secciones en el XAML. Algo como esto:

Por lo que veo, parece que el código está en parte TitleForFooter(tableView, section) pero no estoy seguro de cómo usarlo y cómo podría configurarlo. Tenga en cuenta que realmente no estoy buscando una solución de modelo de vista. Me encantaría poder simplemente especificar el texto del pie de página de sección como parte de TableView XAML.

Agradecería si alguien pudiera darme algún consejo sobre esto.


Es muy simple. necesita agregar la propiedad enlazable para pasar el valor de XAML a CustomRenderer en CustomControl de esta manera:

Tabla de clientes

public class ExtFooterTableView : TableView { public ExtFooterTableView() { } }

Código de control Xaml

<local:ExtFooterTableView x:Name="tableView" Intent="Settings" HasUnevenRows="True">

Clase Renderer

using System; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; using yournamespace; using System.ComponentModel; [assembly: ExportRenderer(typeof(ExtFooterTableView), typeof(FooterTableViewRenderer))] namespace yournamespace { public class FooterTableViewRenderer : TableViewRenderer { protected override void OnElementChanged(ElementChangedEventArgs<TableView> e) { base.OnElementChanged(e); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var view = (ExtFooterTableView)Element; if (e.PropertyName == ExtFooterTableView.IntentProperty.PropertyName) { string intent = view.Intent; // Do your stuff for intent property } if (e.PropertyName == ExtFooterTableView.HasUnevenRowsProperty.PropertyName) { bool hasUnevenRows = view.HasUnevenRows; // Do yout stuff for HasUnevenRow } } } }


En primer lugar, para poder especificar el texto del pie de página de la sección en XAML, la opción más simple sería crear una propiedad TableSection en TableSection . Pero como TableSection está sellado, no podemos derivarlo para definir nuestras propiedades enlazables personalizadas.

Entonces, la siguiente opción es crear una propiedad vinculable adjunta.

public class Ex { public static readonly BindableProperty FooterTextProperty = BindableProperty.CreateAttached("FooterText", typeof(string), typeof(Ex), defaultValue: default(string)); public static string GetFooterText(BindableObject view) { return (string)view.GetValue(FooterTextProperty); } public static void SetFooterText(BindableObject view, string value) { view.SetValue(FooterTextProperty, value); } }

El siguiente paso sería actualizar el renderizador para recuperar este valor para cada sección:

private class CustomFooterTableViewModelRenderer : TableViewModelRenderer { public CustomFooterTableViewModelRenderer(TableView model) : base(model) { } public override UIView GetViewForFooter(UITableView tableView, nint section) { return new UILabel() { Text = TitleForFooter(tableView, section), // or use some other text here Font = UIFont.SystemFontOfSize(14), ShadowColor = Color.White.ToUIColor(), ShadowOffset = new CoreGraphics.CGSize(0, 1), TextColor = Color.DarkGray.ToUIColor(), BackgroundColor = Color.Transparent.ToUIColor(), Opaque = false, TextAlignment = UITextAlignment.Center }; } //Retrieves the footer text for corresponding section through the attached property public override string TitleForFooter(UITableView tableView, nint section) { var tblSection = View.Root[(int)section]; return Ex.GetFooterText(tblSection); } }

Uso de la muestra

<local:ExtFooterTableView x:Name="tableView" Intent="Settings" HasUnevenRows="True"> <TableSection Title="Cards1" local:Ex.FooterText="Sample description"> <ViewCell Height="50"> <Label Margin="20,0,20,0" Text="Hello1" /> </ViewCell> <ViewCell Height="50"> <Label Margin="20,0,20,0" Text="Hello2" /> </ViewCell> </TableSection> <TableSection Title="Cards2" local:Ex.FooterText="Disclaimer note"> <TextCell Height="50" Text="Hello"></TextCell> </TableSection> </local:ExtFooterTableView>