You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using Avalonia.Controls ;
using Avalonia.Controls.Templates ;
using Avalonia.Markup.Xaml.Templates ;
using AI.Models.Form ;
namespace AI.Converters
{
/// <summary>
/// 按表单字段类型选择模板,避免 Boolean 的 CheckBox 与 Choice 的 ComboBox 同屏时互相覆盖 CurrentValue( 如列名 "0" 被写成 "False")。
/// </summary>
public class FormFieldTemplateSelector : IDataTemplate
{
public DataTemplate ? BooleanTemplate { get ; set ; }
public DataTemplate ? ChoiceTemplate { get ; set ; }
public DataTemplate ? DefaultTemplate { get ; set ; }
public Control ? Build ( object? param )
{
if ( param is not FormFieldEntry entry )
{
return null ;
}
var template = entry . Type switch
{
FormFieldType . Boolean = > BooleanTemplate ,
FormFieldType . Choice = > ChoiceTemplate ,
_ = > DefaultTemplate ,
} ;
return template ? . Build ( param ) ;
}
public bool Match ( object? data ) = > data is FormFieldEntry ;
}
}