How to get Event on selected next Tab
Want to load next tab view controller after event trigger.
It create two tab bar for IOS mobile application.
public class TabBarController : UITabBarController {
UIViewController infoController, relatedController,
public TabBarController ()
{
infoController = new UIViewController();
infoController.Title = "Info";
infoController.TabBarItem = new UITabBarItem ("Info", UIImage.FromFile("/Images/first.png"), 0);
infoControllerView.BackgroundColor = UIColor.Orange;
relatedController = new UIViewController();
relatedController.Title = "Related";
relatedController.TabBarItem = new UITabBarItem ("Related", UIImage.FromFile("/Images/second.png"), 1);
relatedController.View.BackgroundColor = UIColor.Orange;
var tabs = new UIViewController[] {
infoController, relatedController
};
ViewControllers = tabs;}}
Second tab will load after a service call result.
based on response data will show result.
Want to know and Event for tab-bar selected tab.
#All
Thanks you in advance.
Related
So I have a LoginPage in my xamarin forms where the user can navigate to by opening the hamburger menu and its one of the HomeMenuItems in my ListView. When the user logs in I navigate back to HomePage and remove the LoginPage from the navigation stack:
var nextPage = new HomePage();
await this.Navigation.PushAsync(nextPage);
Navigation.RemovePage(this);
And also change the Hamburger navigation to add new HomeMenuItems like MyPage and Logout like:
var md = (MasterDetailPage)Application.Current.MainPage;
var menu = (MenuPage)md.Master;
menu.showmychildren();
And it works but when I log out I change back the Hamburger menu to the "logged out version" whenever I try to navigate to the LoginPage it navigates me to the HomePage and I have no idea why it is doing that.
Navigating to LoginPage from hamburger menu:
public void hideall()
{
InitializeComponent();
ucet_stack.IsVisible = false;
ucet.IsVisible = false;
photo_sack.IsVisible = false;
photo.IsVisible = false;
menuItems = new List<HomeMenuItem>
{
new HomeMenuItem {Id = MenuItemType.Home, Title="> HomePage" },
new HomeMenuItem {Id = MenuItemType.Login, Title="> Login" },
new HomeMenuItem {Id = MenuItemType.Sponsors, Title="> Sponsors" }
};
ListViewMenu.ItemsSource = menuItems;
ListViewMenu.SelectedItem = menuItems[0];
ListViewMenu.ItemSelected += async (sender, e) =>
{
if (e.SelectedItem == null)
return;
var id = (int)((HomeMenuItem)e.SelectedItem).Id;
await RootPage.NavigateFromMenu(id);
};
}
And I call:
var md = (MasterDetailPage)Application.Current.MainPage;
var menu = (MenuPage)md.Master;
menu.hideall();
after logging out.
Base on you description, I would give you some suggestions:
1.remove InitializeComponent(); There is no need for you to call this method again.
2.If you want to Navigating to LoginPage from hamburger menu in method hideall(), you can try to change the order of items in menuItems :
menuItems = new List<HomeMenuItem>
{
new HomeMenuItem {Id = MenuItemType.Login, Title="> Login" },
new HomeMenuItem {Id = MenuItemType.Home, Title="> HomePage" },
new HomeMenuItem {Id = MenuItemType.Sponsors, Title="> Sponsors" }
};
Put the Login item as the first element in the array. Once you reset ListViewMenu.ItemsSource in MasterPage, it will show the first page in your menuItems .
3.Through the question and your comments, I'm confused about where is your logOut button located? In the homeMenu? In the loginPage?
4.You navigate pages in the method ListViewMenu.ItemSelected and I think which page to navigate to is depending on the id, so you can add a breakPoint at the line await RootPage.NavigateFromMenu(id); and then check the id of SelectedItem to see if it is the MenuItemType.Login type when you navigate pages.
In my activity I am dynamically creating controls based off of sqlite data. Each item will have a button with a click event that needs to send that rows ID to the new activity.
I have looked at the following page and can get this to work on a button that already exists in my layout. But it doesn't seem to work when the button is dynamically created. Is there something additional I need to do with the button for this to work?
https://developer.xamarin.com/recipes/android/fundamentals/activity/pass_data_between_activity/
Here is the code that creates the button dynamically:
foreach (Tasks item in table)
{
TableRow row = new TableRow(this);
TextView txtTask = new TextView(this);
txtTask.Text = item.Name;
row.AddView(txtTask);
tableLayout.AddView(row);
row = new TableRow(this);
Button btnEdit = new Button(this);
btnEdit.Text = "Edit Record";
btnEdit.SetWidth(300);
btnEdit.Click += delegate
{
Intent viewTask = new Intent(this, typeof(UpdateTaskActivity));
viewTask.PutExtra("TaskId", item.Id);
StartActivity(viewTask);
};
row.AddView(btnEdit);
tableLayout.AddView(row);
}
In the OnCreate method of UpdateTaskActivity I have:
string test = Intent.GetStringExtra("TaskId") ?? "error";
if (test != "error")
{
//Do Stuff
}
But when I put a breakpoint down, my string is always null. I did put a breakpoint to make sure the correct ID is being pulled.
Why does this work with a built in button but does not work with my dynamic one?
Just to avoid confusion, in my startup screen I have a test button, and my main activity has the following code for that button. This code works fine, because the button isn't dymaically created:
//Test button
Button btnTest = FindViewById<Button>(Resource.Id.btnTest);
btnTest.Click += delegate
{
var activity2 = new Intent(this, typeof(UpdateTaskActivity));
activity2.PutExtra("TaskId", "1");
StartActivity(activity2);
};
The main issue is that you are adding an int to the extras:
// item.Id is an int type
viewTask.PutExtra("TaskId", item.Id);
And then you are trying to get it as a string:
var test = Intent.GetStringExtra("TaskId");
There are two ways to get the value, without having to add the value as a string. Either get an int value:
var test = Intent.GetIntExtra("TaskId", 0);
if (test != 0)
{
// Do Stuff
}
Or, you can first check for the extra, if you don't want to rely on the default value:
if (Intent.HasExtra("TaskId"))
{
var test = Intent.GetIntExtra("TaskId", 0);
// Do Stuff
}
Being a newbie to Xamrin I am struggling to adding some HTML to a StackLayout via Xamarin Forms. I have tried quite a few things and had a Google around.
Firstly I can't work out which bindable object I am supposed to be using. As I cannot find a straight answer on Google/Xamarin I am going to assume this is not as easy I was hoping.
var nameEntry = new Label ();
nameEntry.SetBinding (Label.TextProperty, "Club.ClubName");
var webView = new WebView ();
webView.SetBinding ( ??? , "Club.Description");
var content = new StackLayout {
Children = {
nameEntry,
???
}
};
I am not sure if this is possible within Xamarin forms itself. Can anyone help?
I should point out my data for the form is being retrieved asynchronously on a remote json endpoint
protected override void OnAppearing ()
{
base.OnAppearing ();
if (ViewModel == null || ViewModel.IsLoading)
return;
ViewModel.LoadItemsCommand.Execute (Club.ClubId);
}
My remote json api contains, Description contatins a HTML snippet which I would like to use.
{
ClubName: "Stourbridge",
Description: "<p>This club meets every TWO weeks on a <b>Friday</b>.</p>"
...
}
Try the following example that will show how to do the bindings.
Note that you have to use a HtmlWebViewSource to achieve this, and bind the WebView.Source to this.
Clicking the button will change the view model and update the WebView appropriately to the newly changed text.
StackLayout objStackLayout = new StackLayout();
MyView objMyView = new MyView();
objMyView.MyHtml = "<html><head></head><body><h1>Title</h1><p>Some body text</p></body></html>";
HtmlWebViewSource objHtmlWebViewSource = new HtmlWebViewSource();
objHtmlWebViewSource.SetBinding(HtmlWebViewSource.HtmlProperty, "MyHtml");
objHtmlWebViewSource.BindingContext = objMyView;
WebView objWebview = new WebView();
objWebview.HorizontalOptions = LayoutOptions.FillAndExpand;
objWebview.VerticalOptions = LayoutOptions.FillAndExpand;
objWebview.Source = objHtmlWebViewSource;
Button objMyButton2 = new Button();
objMyButton2.Text="Change Html";
objMyButton2.Clicked+=((o2,e2)=>
{
objMyView.MyHtml = "<html><head></head><body><h1>Title</h1><p>Some body text that has changed.</p></body></html>";
});
objStackLayout.Children.Add(objMyButton2);
objStackLayout.Children.Add(objWebview);
The view model is just a simple one with a bindable property as below:-
public class MyView
: Xamarin.Forms.View
{
public static readonly BindableProperty MyHtmlProperty = BindableProperty.Create<MyView, string>(p => p.MyHtml, default(string));
public string MyHtml
{
get { return (string)GetValue(MyHtmlProperty); }
set { SetValue(MyHtmlProperty, value); }
}
}
Before clicking the button gives:-
After clicking the button, adjusts the view model, and automatically updates the control via the binding giving:-
I have a form which contains a dynamically added TableLayoutPanel, which contains some dynamically added Labels, TextBox, CheckBox. I am obtaining exactly the visualization I would like to have, but I am struggling to get the "tab key" to work for moving from one control to the other.
I have tried to add a:
control.TabIndex = tabIndex++;
control.TabStop = true;
But this doesn't seem to have any impact...
This is the (tested) stub code:
class MyForm : Form
{
public MyForm()
{
InitializeComponent();
string[] titles = {"first","second"};
var myLayout = new TableLayoutPanel();
myLayout.AutoSize = true;
int myTabIndex = 1; //Not really necessary
int rowNumber = 0;
foreach (var title in titles)
{
var label = new Label();
label.Text = title;
myLayout.Controls.Add(label, 0, rowNumber);
var control = new TextBox();
control.TabIndex = myTabIndex++; //Not really necessary
myLayout.Controls.Add(control, 1, rowNumber);
rowNumber++;
}
this.Controls.Add(myLayout);
}
}
This is the window I get, and I am not able to navigate from first to second field using the tab key.
Update:
Applying Visual Studio 2013 Update 5 did not help.
Something must have been corrupted in my project. The best I could do is to move on with a new clean Windows Form project, and everything now is working.
I'm trying to create a DevEx drop down button. Unfortunately, I'm running into two problems I can't figure out:
1) I can't get the popup menu to skin correctly, i.e. it doesn't skin as "Office 2010 Blue". The code I'm using is shown below:
private void InitializeSendToPricingSheetButton()
{
var barManager = new BarManager();
if (barManager.Controller == null) barManager.Controller = new BarAndDockingController();
barManager.Controller.PaintStyleName = "Skin";
barManager.Controller.LookAndFeel.UseDefaultLookAndFeel = false;
barManager.Controller.LookAndFeel.SkinName = "Office 2010 Blue";
barManager.ItemClick += HandleSendToPricingSheetClick;
barManager.Items.AddRange(new[] { new BarButtonItem(barManager, "Foo"), new BarButtonItem(barManager, "Bar"), new BarButtonItem(barManager, "Baz") });
var popupMenu = new PopupMenu { Manager = barManager };
foreach (var barItem in barManager.Items) popupMenu.ItemLinks.Add((BarItem)barItem);
popupMenu.ItemLinks[1].BeginGroup = true;
dropDownButtonSendToPricingSheet.DropDownControl = popupMenu;
}
2) This button is on a form. If the form loses focus (e.g. I click on Firefox), the pop-up menu still remains on-top. It won't go away until clicked.
Any suggestions would be much appreciated. Thanks for helping me deal with DevEx insanity.
I have solution to your second question.
You should add drop down button event handler as below:
dropDownButton1.LostFocus += new EventHandler(HidePopUp);
Handler method should be as below:
private void HidePopUp(object sender,object e)
{
dropDownButton1.HideDropDown();
}
For your second question, you should assign value to the bar manager property as:
BarManager manager = new BarManager();
manager.Form = this; // refers to current form
Find below link for reference
https://www.devexpress.com/Support/Center/Question/Details/Q274641
It is probably simpler to use DefaultLookAndFeel
Add this comp to your form and set the theme you'd like to use.
There is no need to set the theme for individual components.
defaultLookAndFeel1.LookAndFeel.SetSkinStyle("Office 2010 Blue");