2017-01-16 48 views
1

我想转换以下XAML改用ViewCell在C#中定义一个定制的...Xamarin形式 - C#相当于XAML绑定

​​

转换我之后所以......

<ListView x:Name="___listview" HasUnevenRows="True"> 
    <ListView.ItemTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

和C#...

public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
     ___listview.ItemsSource = Repository.GetList(); 
     ___listview.ItemTemplate = new DataTemplate(typeof(CustomViewCell)); 
    } 
} 

public class CustomViewCell : ViewCell 
{ 
    bool _initialized = false; 

    public CustomViewCell() 
    { 
     var stack = new StackLayout(); 

     var button = new Button(); 

     stack.Children.Add(button); 

     View = stack; 
    } 
} 

什么代码需要完成绑定语法上的按钮的Image一nd Command属性在XAML中已完成?

回答

4
var button = new Button(); 
button.SetBinding(Button.ImageProperty, new Binding("ImageName")); 
button.SetBinding(Button.CommandProperty, new Binding("ShowDetailsCommand"));