本文整理汇总了C#中Xamarin.Forms.DataTemplate.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# DataTemplate.SetBinding方法的具体用法?C# DataTemplate.SetBinding怎么用?C# DataTemplate.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Xamarin.Forms.DataTemplate
的用法示例。
在下文中一共展示了DataTemplate.SetBinding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodedPage
public CodedPage ()
{
_SomeLabel = new Label {
XAlign = TextAlignment.Center,
};
_SomeLabel.SetBinding (Label.TextProperty, nameof (SomeViewModel.SomeLabel));
var listViewItemTemplate = new DataTemplate (typeof(ImageCell));
_ItemsListView = new ListView (ListViewCachingStrategy.RecycleElement) {
ItemTemplate = listViewItemTemplate,
};
_ItemsListView.SetBinding (ListView.ItemsSourceProperty, nameof (SomeViewModel.SomeItems));
listViewItemTemplate.SetBinding (ImageCell.TextProperty, nameof (SomeItem.ItemName));
listViewItemTemplate.SetBinding (ImageCell.ImageSourceProperty, nameof (SomeItem.ImageUrl));
_ItemsListView.ItemTapped += async (sender, e) => {
var item = ((SomeItem)e.Item);
ItemSelected (this, item);
_ItemsListView.SelectedItem = null;
};
Padding = new Thickness (0, 20, 0, 0);
Content = new StackLayout {
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Children = {
_SomeLabel,
_ItemsListView,
}
};
}
示例2: Init
private async Task Init ()
{
_conferencesListView = new ListView {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
};
var cell = new DataTemplate (typeof(TextCell));
cell.SetBinding (TextCell.TextProperty, "Name");
cell.SetBinding (TextCell.DetailProperty, new Binding (path: "Start", stringFormat: "{0:MM/dd/yyyy}"));
_conferencesListView.ItemTemplate = cell;
var viewModel = new ConferencesViewModel ();
await viewModel.GetConferences ();
_conferencesListView.ItemsSource = viewModel.Conferences;
this.Content = new StackLayout {
VerticalOptions = LayoutOptions.FillAndExpand,
Padding = new Thickness (
left: 0,
right: 0,
bottom: 0,
top: Device.OnPlatform (iOS: 20, Android: 0, WinPhone: 0)),
Children = {
_conferencesListView
}
};
}
示例3: FcpChampions
///<summary>FcpChampions: Displays a listview of all champions.
///<para>[Navigation] From: MainPage / Calls: FcpTabChampions</para>
///</summary>
public FcpChampions() {
//NavigationPage.SetBackButtonTitle(this, "Back to menu");
this.Title = "Champions";
stacklayout.VerticalOptions = LayoutOptions.FillAndExpand;
stacklayout.BackgroundColor = Color.Red ;
//ReadChampionJson();
//ReceiveChampions();
FillViewChampions();
var cell = new DataTemplate(typeof(ImageCell));
cell.SetBinding(ImageCell.ImageSourceProperty, "Image");
cell.SetBinding(TextCell.TextProperty, "Name");
cell.SetBinding(TextCell.TextColorProperty, "Color");
listview.ItemTemplate = cell;
listview.ItemsSource = Cells;
listview.ItemTapped += Listview_ItemTapped;
listview.BackgroundColor = Color.Black;
searchbar.Placeholder = "Find champion";
searchbar.TextChanged += Searchbar_TextChanged;
searchbar.BackgroundColor = Color.Black;
Content = stacklayout;
stacklayout.Children.Add(searchbar);
stacklayout.Children.Add(listview);
}
示例4: ContactsPage
public ContactsPage()
{
contactsList = new ListView();
var cell = new DataTemplate(typeof(TextCell));
cell.SetBinding(TextCell.TextProperty, "FirstName");
cell.SetBinding(TextCell.DetailProperty, "LastName");
contactsList.ItemTemplate = cell;
contactsList.ItemSelected += (sender, args) =>
{
if (contactsList.SelectedItem == null)
return;
var contact = contactsList.SelectedItem as Contact;
Navigation.PushAsync(new ContactPage(contact));
contactsList.SelectedItem = null;
};
Content = contactsList;
}
示例5: RssFeedView2
public RssFeedView2()
{
this.viewModel = new RssFeedViewModel();
this.BindingContext = viewModel;
this.Title = "Rss Feed";
var refresh = new ToolbarItem(){ Command = viewModel.ReloadCommand, Name = "Reload", Priority = 0 };
ToolbarItems.Add(refresh);
var stack = new StackLayout(){ Orientation = StackOrientation.Vertical };
var activity = new ActivityIndicator(){ Color = Color.Blue, IsEnabled = true };
activity.SetBinding(ActivityIndicator.IsVisibleProperty, "ShowActivityIndicator");
activity.SetBinding(ActivityIndicator.IsRunningProperty, "ShowActivityIndicator");
stack.Children.Add(activity);
var listview = new ListView();
listview.ItemsSource = viewModel.Records;
var cell = new DataTemplate(typeof(ImageCell));
cell.SetBinding(ImageCell.TextProperty, "Title");
cell.SetBinding(ImageCell.ImageSourceProperty, "Image");
listview.ItemTemplate = cell;
listview.ItemSelected += async (sender, e) => {
await Navigation.PushAsync(new RssWebView((RssRecordViewModel)e.SelectedItem));
listview.SelectedItem = null;
};
stack.Children.Add(listview);
Content = stack;
}
示例6: FoodCategoryPage
public FoodCategoryPage ()
{
Title = "Food";
Padding = new Thickness (10, 20);
var places = new List<Place> ()
{
new Place("McDonalds", "mcdonalds.png", "1010 S McKenzie St Foley, AL"),
new Place("Burger King", "burgerKing.png", "910 S McKenzie St Foley AL"),
new Place("Apple Bees", "appleBees.png", "2409 S McKenzie St, Foley, AL"),
new Place("Taco Bell", "tacoBell.jpg", "1165 S McKenzie St, Foley, AL"),
new Place("Subway", "subway.jpg", "610 S McKenzie St Foley, AL")
};
var imageTemplate = new DataTemplate (typeof(ImageCell));
imageTemplate.SetBinding (ImageCell.TextProperty, "Name");
imageTemplate.SetBinding (ImageCell.ImageSourceProperty, "Icon");
imageTemplate.SetBinding (ImageCell.DetailProperty, "Address");
var listView = new ListView ()
{
ItemsSource = places,
ItemTemplate = imageTemplate
};
Content = listView;
}
示例7: SetupUI
private void SetupUI()
{
BackgroundColor = Color.White;
var cell = new DataTemplate (typeof(HiveListCell));
cell.SetBinding (HiveListCell.HeadingTextProperty, "DisplayName");
cell.SetBinding (HiveListCell.MiddleTextProperty, "ReadDate");
cell.SetBinding (HiveListCell.LowerTextProperty, "Humidity");
// cell.SetBinding (HiveListCell.BottomTextProperty, "Humidity");
//cell.SetBinding (HiveListCell.BottomUUIDProperty, "DisplayUUIDName");
//cell.SetBinding (HiveListCell.HiveAddressProperty, "Address");
listOfReadings = new ListView (ListViewCachingStrategy.RetainElement);
listOfReadings.HasUnevenRows = true;
listOfReadings.BindingContext = ListReadings;
listOfReadings.SetBinding (ListView.ItemsSourceProperty, ".");
listOfReadings.ItemTemplate = cell;
listOfReadings.BackgroundColor = Color.White;
Content = new StackLayout {
Children = {
listOfReadings
},
Padding = new Thickness (0, 0, 0, 1)
};
}
示例8: KnockoutMatchView
public KnockoutMatchView()
{
BindingContext = new KnockoutMatchesViewModel();
var refresh = new ToolbarItem {
Command = ViewModel.LoadItemsCommand,
Icon = "refresh.png",
Name = "refresh",
Priority = 0
};
ToolbarItems.Add (refresh);
var stack = new StackLayout {
Orientation = StackOrientation.Vertical,
Padding = new Thickness(0, 8, 0, 8)
};
var listView = new ListView ();
listView.ItemsSource = ViewModel.KnockoutMatches;
var cell = new DataTemplate(typeof(ListTextCell));
cell.SetBinding (TextCell.TextProperty, "KnockoutMatchName");
cell.SetBinding (TextCell.DetailProperty, "KnockoutMatchTeams");
listView.ItemTemplate = cell;
stack.Children.Add (listView);
Content = stack;
}
示例9: Init
public void Init()
{
if (Device.OS == TargetPlatform.iOS) {
var list = new EditableListView<Object> ();
list.SetBinding (EditableListView<Object>.SourceProperty, "JellyBeanValues");
list.ViewType = typeof(JellyBeanListViewCell);
list.CellHeight = 60;
list.AddRowCommand = new Command (() => {
this.DisplayAlert ("Sorry", "Not implemented yet!", "OK");
});
if (PageModel.JellyBeanValues != null)
list.Source = PageModel.JellyBeanValues;
Content = list;
} else {
var list = new ListView();
list.SetBinding (ListView.ItemsSourceProperty, "JellyBeanValues");
var celltemp = new DataTemplate(typeof(TextCell));
celltemp.SetBinding (TextCell.TextProperty, "Name");
celltemp.SetBinding (TextCell.DetailProperty, "ReadableValues");
list.ItemTemplate = celltemp;
if (PageModel.JellyBeanValues != null)
list.ItemsSource = PageModel.JellyBeanValues;
Content = list;
}
ToolbarItems.Add(new ToolbarItem("Add", "", () => {
this.DisplayAlert("Sorry", "Not implemented yet!", "OK");
}));
}
示例10: ListaNotificaciones
public ListaNotificaciones()
{
//notificaciones = new Notificacion ("Red Social","BtoB");
var cell = new DataTemplate (typeof(TextCell));
cell.SetBinding (TextCell.TextProperty, "Title");
cell.SetBinding (TextCell.DetailProperty, "Subtitle");
ItemTemplate = cell;
var loc = new List<Notificacion> () {
new Notificacion ("Abercrombie & Fitch / abercrombie kids", "Level 2 | (480) 792-9275"),
new Notificacion ("ALDO", "Level 2 | (480) 899-0803"),
new Notificacion ("All Mobile Matters Mobile Phone Repair & More", "Level 2 | (480) 228-9690"),
new Notificacion ("Alterations By L", "Level 1 | (480) 786-8092"),
new Notificacion ("AMERICAN EAGLE OUTFITTERS", "Level 2 | (480) 812-0090"),
new Notificacion ("Ann Taylor", "Level 1 | (480) 726-6944"),
new Notificacion ("Apex by sunglass hut", "Level 2 | (480) 855-1709")
};
ItemsSource = loc;
/*ItemSelected += (s, e) => {
if (SelectedItem == null)
return;
var selected = (Notificacion)e.SelectedItem;
SelectedItem = null;
//Navigation.PushAsync (new CampusLocationPage (selected));
};*/
}
示例11: FeedOverview
public FeedOverview()
{
var refreshButton = new Button {
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Text = "Refresh"
};
refreshButton.SetBinding(Button.CommandProperty, "RefreshCommand");
var template = new DataTemplate(typeof(TextCell));
// We can set data bindings to our supplied objects.
template.SetBinding(TextCell.TextProperty, "Title");
template.SetBinding(TextCell.DetailProperty, "Description");
var listView = new ListView {ItemTemplate = template};
listView.SetBinding(ListView.ItemsSourceProperty, "FeedItems");
// Push the list view down below the status bar on iOS.
Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);
Content = new Grid {
BindingContext = new FeedReaderViewModel(),
RowDefinitions = new RowDefinitionCollection {
new RowDefinition { Height = new GridLength (1, GridUnitType.Star) },
new RowDefinition { Height = new GridLength (0, GridUnitType.Auto) },
},
Children = {
new ViewWithGridPosition(listView, 0,0),
new ViewWithGridPosition(refreshButton, 1,0)
},
};
}
示例12: SchoolPickerPage
public SchoolPickerPage(LoginPage page)
{
InitializeComponent ();
_Context = SynchronizationContext.Current;
Search.TextChanged += (object sender, TextChangedEventArgs e) =>
{
if ((DateTime.Now - _PreviousGet).TotalSeconds < 4 && Search.Text.Length > 3)
{
GetSchoolData();
_PreviousGet = DateTime.Now;
}
};
Search.SearchButtonPressed += (object sender, EventArgs e) => {
GetSchoolData();
_PreviousGet = DateTime.Now;
};
var SchoolTemplate = new DataTemplate (typeof(Xamarin.Forms.TextCell));
SchoolTemplate.SetBinding (TextCell.TextProperty, new Binding ("Name"));
SchoolTemplate.SetBinding (TextCell.DetailProperty, new Binding ("Url"));
Results.ItemTemplate = SchoolTemplate;
Results.ItemTapped += (object sender, ItemTappedEventArgs e) => {
page.SelectSchool((Magister.School)e.Item);
Navigation.PopModalAsync();
};
}
示例13: Offers
public Offers ()
{
//commented out dummy offers
//setOffers ();
Title = "Offers";
Icon = "Offers.png";
// Create a data template from the type ImageCell
var cell = new DataTemplate (typeof(ImageCell));
cell.SetBinding (TextCell.TextProperty, "Name");
cell.SetBinding (TextCell.DetailProperty,"Description");
cell.SetBinding (ImageCell.ImageSourceProperty, "Image");
ListView listView = new ListView {
ItemsSource = offers,
ItemTemplate = cell // Set the ImageCell to the item template for the listview
};
// Push the list view down below the status bar on iOS.
this.Padding = new Thickness (10, Device.OnPlatform (20, 0, 0), 10, 5);
// Set the content for the page.
this.Content = new StackLayout {
Children = {
//header,
listView
}
};
}
示例14: MenuLayout
/// <summary>
/// Menu Page Layout.
/// </summary>
public void MenuLayout()
{
List<MenuModel> data = MenuModel.MenuListData();
listMenu = new ListView { RowHeight = 40, SeparatorColor = Color.FromHex("#5B5A5F") };
listMenu.VerticalOptions = LayoutOptions.FillAndExpand;
listMenu.BackgroundColor = Color.Transparent;
listMenu.ItemsSource = data;
var cell = new DataTemplate(typeof(MenuCell));
cell.SetBinding(MenuCell.TextProperty, "Title");
cell.SetBinding(MenuCell.ImageSourceProperty, "IconSource");
listMenu.ItemTemplate = cell;
//var menuLabel = new ContentView
//{
// Padding = new Thickness(10, 36, 0, 5),
// Content = new Label
// {
// TextColor = Color.FromHex("AAAAAA"),
// Text = "MENU",
// }
//};
this.Content = new StackLayout
{
BackgroundColor = Color.White,
Children = { listMenu }
};
}
示例15: ListViewEx
public ListViewEx()
{
var classNames = new[]
{
"Building Cross Platform Apps with Xamarin Part1",
"Building Cross Platform Apps with Xamarin Part2",
"Building Cross Platform Apps with Xamarin Part3"
};
//TODO: Translate into XAML
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
var listView = new ListView();
//listView.ItemsSource = classNames;
listView.ItemsSource = PluralsightCourse.GetCourseList();
var cell = new DataTemplate(typeof(TextCell));
//cell.SetBinding(TextCell.TextProperty, new Binding("."));
cell.SetBinding(TextCell.TextProperty, new Binding("Title"));
cell.SetBinding(TextCell.DetailProperty, new Binding("Author"));
cell.SetValue(TextCell.TextColorProperty, Color.Red);
cell.SetValue(TextCell.DetailColorProperty,Color.Yellow);
listView.ItemTemplate = cell;
Content = listView;
}