我想在“选择器”中添加一个自定义文本。我有一个选择器,可以从我的数据库中绑定 ItemsSource 和 ItemDisplayBinding ,如何将自定义文本添加到 ItemDisplayBinding 我想将零售商代码与 PresStreet 混合并格式化为“零售商代码-街道” ,我的表格在下面供参考
Picker标题=“选择零售商代码” x:Name =“ codePicker” SelectedIndexChanged =“ codePicker_SelectedIndexChanged” ItemsSource =“ {Binding RetailerCode}” ItemDisplayBinding =“ {Binding RetailerCode}” StyleClass =“ fieldForm” IsEnabled =“ False” < / p>
下面的代码是如何从数据库中获取数据并将数据添加到选择器中
var db = DependencyService.Get<ISQLiteDB>();
var conn = db.GetConnection();
var getCode = conn.QueryAsync<RetailerGroupTable>("SELECT * FROM tblRetailerGroup WHERE ContactID=?", item.ContactID);
var resultCount = getCode.Result.Count;
if (resultCount > 0)
{
var result = getCode.Result;
codePicker.ItemsSource = result;
codePicker.IsEnabled = true;
}
else
{
lstName.IsVisible = false;
codePicker.IsEnabled = false;
}
我的零售商组表:
[Table("tblRetailerGroup")]
public class RetailerGroupTable
{
[PrimaryKey, MaxLength(100)]
public string RetailerCode { get; set; }
public int ContactID { get; set; }
[MaxLength(300)]
public string PresStreet { get; set; }
[MaxLength(90)]
public string PresBarangay { get; set; }
[MaxLength(90)]
public string PresDistrict { get; set; }
[MaxLength(90)]
public string PresTown { get; set; }
[MaxLength(90)]
public string PresProvince { get; set; }
[MaxLength(90)]
public string PresCountry { get; set; }
[MaxLength(30)]
public string Telephone1 { get; set; }
[MaxLength(30)]
public string Telephone2 { get; set; }
[MaxLength(20)]
public string Mobile { get; set; }
[MaxLength(50)]
public string Email { get; set; }
[MaxLength(200)]
public string GPSCoordinates { get; set; }
[MaxLength(100)]
public string Coordinator { get; set; }
public DateTime LastSync { get; set; }
public DateTime ServerUpdate { get; set; }
public DateTime MobileUpdate { get; set; }
}
答案 0 :(得分:1)
向您的类RetailerGroupTable添加只读属性
taskService.createTaskQuery().processDefinitionKey( your process definition key);
然后绑定到它
public string DisplayText {
get {
return $"{RetailerCode} - {PresStreet}";
}
}