2017-01-16 49 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"));