2
これまでこのコードを思いつきました。私の問題はレンダラーにスタイルを渡したいのですが、スタイルIDを渡す方法がわかりません。Xamarin Labelカスタムレンダラにスタイルリクエストを渡す方法はありますか?
public class LabelBodyCustomRenderer : LabelRenderer
{
public LabelBodyCustomRenderer()
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
Control.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Body);
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == Label.TextColorProperty.PropertyName
|| e.PropertyName == Label.FontProperty.PropertyName
|| e.PropertyName == Label.TextProperty.PropertyName
|| e.PropertyName == Label.FormattedTextProperty.PropertyName)
{
switch (e.StyleId)
{
case "Body":
Control.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Body);
break;
case "Callout":
Control.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Callout);
break;
case "Caption1":
Control.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Caption1);
break;
case "Caption2":
Control.Font = UIFont.GetPreferredFontForTextStyle(UIFontTextStyle.Caption2);
break;
case "Footnote":
このようにして、コードでitem.StyleIdを使用した別の例を見ました。 - mylabelというの
public class TextCellCustomRenderer : TextCellRenderer
{
CellTableViewCell cell;
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var textCell = (TextCell)item;
var fullName = item.GetType().FullName;
cell = tv.DequeueReusableCell(fullName) as CellTableViewCell;
if (cell == null)
{
cell = new CellTableViewCell(UITableViewCellStyle.Value1, fullName);
}
else
{
cell.Cell.PropertyChanged -= cell.HandlePropertyChanged;
//cell.Cell.PropertyChanged -= Current_PropertyChanged;
}
こんにちは、ちょっと例を挙げてください。私はどこから始めるべきか分かりません。もう少しCSを表示し、おそらくXAMLのために1行を表示できますか? –
更新されました。 –