本文整理汇总了C#中ContentPage.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# ContentPage.SetBinding方法的具体用法?C# ContentPage.SetBinding怎么用?C# ContentPage.SetBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContentPage
的用法示例。
在下文中一共展示了ContentPage.SetBinding方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TemplatedTabbedGallery
public TemplatedTabbedGallery()
{
Title = "Templated Tabbed Gallery";
_items = new ObservableCollection<Item> {
CreateItem(),
CreateItem()
};
ItemsSource = _items;
ItemTemplate = new DataTemplate (() => {
var page = new ContentPage();
page.SetBinding (TitleProperty, "Title");
page.SetBinding (IconProperty, "Icon");
var layout = new StackLayout();
var label = new Label();
label.SetBinding (Label.TextProperty, "Content");
layout.Children.Add (label);
var add = new Button ();
add.SetBinding (Button.TextProperty, "InsertTabText");
add.Clicked += (sender, args) => _items.Insert (_items.IndexOf ((Item)add.BindingContext) + 1, CreateItem());
layout.Children.Add (add);
var titleNum = 0;
var change = new Button ();
change.SetBinding (Button.TextProperty, "ChangeTitleText");
change.Clicked += (sender, args) => ((Item) change.BindingContext).Title = ("Title: " + titleNum++);
layout.Children.Add (change);
var move = new Button ();
move.SetBinding (Button.TextProperty, "MoveTabText");
move.Clicked += (sender, args) => {
int originalIndex = _items.IndexOf ((Item) add.BindingContext);
int index = originalIndex + 1;
if (index == _items.Count)
index = 0;
_items.Move (originalIndex, index);
};
layout.Children.Add (move);
var remove = new Button ();
remove.SetBinding (Button.TextProperty, "RemoveTabText");
remove.Clicked += (sender, args) => {
if (_items.Count == 0) {
layout.Children.Add (new Label {
Text = "No more tabs"
});
}
_items.Remove ((Item)remove.BindingContext);
};
layout.Children.Add (remove);
var reset = new Button ();
reset.SetBinding (Button.TextProperty, "ResetAllTabsText");
reset.Clicked += (sender, args) => {
_count = 0;
ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
};
layout.Children.Add (reset);
var nextPage = new Button ();
nextPage.SetBinding (Button.TextProperty, "NextPageText");
nextPage.Clicked += (sender, args) => {
int index = _items.IndexOf ((Item) nextPage.BindingContext) + 1;
if (index == _items.Count)
index = 0;
SelectedItem = _items[index];
};
layout.Children.Add (nextPage);
page.Content = new ScrollView {
Padding = new Thickness (20, 0),
Content = layout
};
return page;
});
}
示例2: TemplatedCarouselGallery
public TemplatedCarouselGallery()
{
NavigationPage.SetHasNavigationBar (this, false);
_items = new ObservableCollection<Item> {
CreateItem(),
CreateItem(),
};
ItemsSource = _items;
ItemTemplate = new DataTemplate (() => {
var page = new ContentPage ();
page.Padding = new Thickness (0,30,0,0);
page.SetBinding (TitleProperty, "Title");
var layout = new StackLayout { Spacing = 0 };
var label = new Label();
label.SetBinding (Label.TextProperty, "Content");
layout.Children.Add (label);
var swipeHereLabel = new Label {
Text = "Swipe Here",
HeightRequest = 40
};
layout.Children.Add (swipeHereLabel);
var add = new Button ();
add.SetBinding (Button.TextProperty, "InsertTabText");
add.Clicked += (sender, args) => _items.Insert (_items.IndexOf ((Item)add.BindingContext) + 1, CreateItem());
layout.Children.Add (add);
var change = new Button ();
change.SetBinding (Button.TextProperty, "ChangeTitleText");
change.Clicked += (sender, args) => ((Item) change.BindingContext).Title = (new Random().Next().ToString());
layout.Children.Add (change);
var remove = new Button ();
remove.SetBinding (Button.TextProperty, "RemoveTabText");
remove.Clicked += (sender, args) => _items.Remove ((Item)remove.BindingContext);
layout.Children.Add (remove);
var reset = new Button ();
reset.SetBinding (Button.TextProperty, "ResetAllTabsText");
reset.Clicked += (sender, args) => {
_count = 0;
ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
};
layout.Children.Add (reset);
var nextPage = new Button ();
nextPage.SetBinding (Button.TextProperty, "NextPageText");
nextPage.Clicked += (sender, args) => {
int index = _items.IndexOf ((Item) nextPage.BindingContext) + 1;
if (index == _items.Count)
index = 0;
SelectedItem = _items[index];
};
layout.Children.Add (nextPage);
var delayReset = new Button { Text = "Delayed reset" };
delayReset.SetBinding (Button.TextProperty, "DelayedResetText");
delayReset.Clicked += (sender, args) => {
ItemsSource = null;
Task.Delay (5000).ContinueWith (t => {
_count = 0;
ItemsSource = _items = new ObservableCollection<Item> { CreateItem(), CreateItem() };
}, TaskScheduler.FromCurrentSynchronizationContext());
};
layout.Children.Add (delayReset);
page.Content = new ScrollView {
Padding = new Thickness (60, 0),
Content = layout
};
return page;
});
}
示例3: BackgroundImageGallery
public BackgroundImageGallery ()
{
var contentIntabs = new Button { Text = "Tabbed children" };
contentIntabs.Clicked += async (sender, args) => {
await Navigation.PushModalAsync (new TabbedPage {
ItemTemplate = new DataTemplate (() => {
var page = new ContentPage();
page.SetBinding (BackgroundImageProperty, ".");
return page;
}),
ItemsSource = new[] {
"oasis.jpg",
"crimson.jpg"
}
/*ItemsSource = new[] {
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-21.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-31.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-61.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-71.jpg"
};*/
});
};
var contentInCarosel = new Button { Text = "Carousel children" };
contentInCarosel.Clicked += async (sender, args) => {
await Navigation.PushModalAsync (new CarouselPage {
ItemTemplate = new DataTemplate (() => {
var page = new ContentPage();
page.SetBinding (BackgroundImageProperty, ".");
return page;
}),
ItemsSource = new[] {
"oasis.jpg",
"crimson.jpg"
}
/*ItemsSource = new[] {
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-21.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-31.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-61.jpg",
"http://www.zemwallpaper.com/wp-content/uploads/2014/05/Desktop-background-download-71.jpg"
};*/
});
};
var navigation = new Button { Text = "NavigationPage"};
navigation.Clicked += async (sender, args) => {
await Navigation.PushModalAsync (new NavigationPage (new ContentPage {
Content = new Label {
Text = "Text",
FontSize = 42
}})
{
BackgroundImage = "oasis.jpg"
}
);
};
var carousel = new Button { Text = "CarouselPage" };
carousel.Clicked += async (sender, args) => {
await Navigation.PushAsync (new CarouselPage {
BackgroundImage = "crimson.jpg",
ItemsSource = new[] { "test1", "test2" }
});
};
var tabbed = new Button { Text = "TabbedPage" };
tabbed.Clicked += async (sender, args) => {
await Navigation.PushAsync (new TabbedPage {
BackgroundImage = "crimson.jpg",
ItemsSource = new[] { "test1", "test2" }
});
};
var master = new Button { Text = "MasterDetail" };
master.Clicked += async (sender, args) => {
await Navigation.PushModalAsync (new MasterDetailPage {
Master = new ContentPage { Title = "Master" },
Detail = new ContentPage(),
BackgroundImage = "crimson.jpg",
});
};
Content = new StackLayout {
Children = {
navigation,
carousel,
tabbed,
master,
contentIntabs,
contentInCarosel
}
};
}