【问题标题】:How to bind the custom control template into native control如何将自定义控件模板绑定到本机控件
【发布时间】:2014-12-26 06:03:49
【问题描述】:

我已经创建了类似于多选列表框的自定义控件,我有模板属性,我需要将模板绑定到本机控件列表中,

<local:MyList.Template>
   <DataTemplate>
     <Label Text="{Binding Description}" BackgroundColor="White" TextColor="Black" XAlign="Center" YAlign="Center"></Label>
   </DataTemplate>
 </local:MyList.Template>

我需要这个标签数据模板到本机控件中,在 WP 中我们有模板,因此我可以轻松地与本机控件绑定。但我无法为 Android 和 iOS 获得它。对于 xamarin 形式。

问题是“如何将自定义控件模板绑定到原生控件中”?

【问题讨论】:

    标签: c# android ios datatemplate xamarin.forms


    【解决方案1】:

    例如,这里是我根据 MS Xaml ItemsControl 建模的 ItemsView 的项目创建代码。这是相当基本的,但可以完成我需要的工作。

    View CreateNewItem(object context)
    {
    var view = this.ItemTemplate.CreateContent() as View;
    view.BindingContext = context;
    return view;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-03
      • 2010-12-28
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      相关资源
      最近更新 更多