Is there a way in Xamarin.Forms to handle view containment? Let's say I want to build a vertical TabBar with a container. Normally in iOS I'd utilize a Container View and in Android I'd use Fragments. How would I do this in Xamarin.Forms?
Xamarin.Forms has a TabbedPage Setting the title of the sub pages populates the tabs with their text.
public class MyTabbedPage: TabbedPage
{
public MyTabbedPage()
{
var firstPage = new MyFirstPage
{
Title = "My First Page"
};
var secondPage = new MySecondPage
{
Title = "My Second Page"
};
Title = "Title of my Tabbed Page";
Children.Add(firstPage);
Children.Add(secondPage);
}
}
Related
I have a lookup view on my xamarin.iOS app where the user puts their subdomain in and I want the textbox to be to the left of the label that has the parent domain, the image below shows what I basically want to achieve:
I was easily able to achieve this on android using drawables but my iOS skills are not as sharp so I'm lost on how I do this on iOS.
in iOS ,you can implment it in code.
in xxxViewController
public override void ViewDidLoad()
{
base.ViewDidLoad();
UIView backgroundView = new UIView(new CGRect(10,50,View.Bounds.Width-20,30));
UILabel domainLab = new UILabel()
{
Text = " https://www.example.com ",
Font = UIFont.SystemFontOfSize(12),
TextColor = UIColor.Gray ,
BackgroundColor=UIColor.LightGray,
Frame=new CGRect(0,0,150,30)
};
UITextField textField = new UITextField()
{
Frame=new CGRect(150,0,View.Bounds.Width-170,30),
};
textField.Layer.MasksToBounds = true;
textField.Layer.BorderColor = UIColor.LightGray.CGColor;
textField.Layer.BorderWidth = (System.nfloat)0.5;
backgroundView.AddSubview(domainLab);
backgroundView.AddSubview(textField);
View.AddSubview(backgroundView);
// Perform any additional setup after loading the view, typically from a nib.
}
I am creating a page where on click of a button a popover should appear as that in screenshot attached.
I have almost tried many methods to do so.but all ended up showing full screen.Is there really not any way to create a popover in Xamarin iOS?
Can any one help me with this?enter image description here
You can construct the custom pop view controller, then present it with the UIModalPresentationStyle Popover:
//The pop view controller you want to show, here I use Storyboard to initialize it
PopoverViewController popViewController = Storyboard.InstantiateViewController("PopoverViewController") as PopoverViewController;
//Set the presentation style to popover
popViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
//The popover view's size
popViewController.PreferredContentSize = new CGSize(150, 150);
//The pop view's position
popViewController.PopoverPresentationController.SourceView = MyBtn;
popViewController.PopoverPresentationController.SourceRect = MyBtn.Bounds;
popViewController.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Up;
//We can also customize the background color
//popViewController.PopoverPresentationController.BackgroundColor = UIColor.White;
popViewController.PopoverPresentationController.Delegate = new PopOverViewDelegate();
PresentModalViewController(popViewController, true);
Do not forget to set the delegate below to achieve the same effect on iPhone:
public class PopOverViewDelegate : UIPopoverPresentationControllerDelegate
{
public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
return UIModalPresentationStyle.None;
}
}
This question is specific to the NavigationController in the Material iOS framework by CosmicMind. https://github.com/CosmicMind/Material
It looks like the backButtonImage is a public property
public var backButtonImage: UIImage? {
didSet {
if nil == backButtonImage {
backButtonImage = MaterialIcon.arrowBack
}
}
}
I can't seem to set it properly.
(navigationBar as! NavigationBar).backButtonImage = UIImage.fontAwesomeIconWithName(.ChevronLeft, textColor: colorKit.headerTitleText, size: CGSizeMake(30,30))
The framework doesn't include the Material icons, so the back button appears as an empty button by default, which might be confusing to people.
In Material 1.37.0, you can do this:
(navigationBar as? NavigationBar)?.backButtonImage = UIImage(named: "ic_icon_name")
I am creating an iPad app using MonoTouch 2.10.11 and I want to MonoTouch.Dialog to create some of the editable fields on a form. One of the fields will use a RadioGroup to allow the user to select from a list of options. The default behavior of M.T.D is display the selection list table over the existing table. This works great for the iPhone layout, but on this iPad form, the table is only on a small area of the form and the navigation bar looks odd on the middle of the form. I want to display the selection as a full screen modal and the user will hit a "back" button to go back the previous form with the selected item.
I created a new RootElement descendant class like this:
public class ModalRootElement : RootElement
{
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
tableView.DeselectRow (path, false);
UIViewController uIViewController = this.MakeViewController ();
this.PrepareDialogViewController (uIViewController);
dvc.PresentViewController (uIViewController, true, null);
}
protected override void PrepareDialogViewController(UIViewController dvc)
{
base.PrepareDialogViewController(dvc);
UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
button.Frame = new RectangleF (5, 5, 80, 20);
button.SetTitle ("back", UIControlState.Normal);
button.TouchUpInside += delegate {
DialogViewController d = dvc as DialogViewController;
(d.Root as ModalRootElement).TableView.ReloadData ();
d.DeactivateController(true);
};
dvc.View.AddSubview (button);
}
}
The table is implemented with the following code:
var _status = new ModalRootElement("Status", new RadioGroup("status", -1)) {
(new Section() {
new RadioElement("New", "status"),
new RadioElement("In process", "status"),
new RadioElement("Rejected", "status"),
new RadioElement("Deferred", "status"),
new RadioElement("Transferred", "status"),
new RadioElement("Unknown", "status"),
new RadioElement("Complete", "status")
})
};
var _odom = new EntryElement ("Odometer", "current odom", "");
_odom.KeyboardType = UIKeyboardType.DecimalPad;
_odom.TextAlignment = UITextAlignment.Right;
var root = new RootElement ("back") {
new Section("") {
_status,
_odom
}
};
_dvc = new DialogViewController(root);
_nav = new UINavigationController (_dvc);
_nav.SetNavigationBarHidden (true, false);
When I run the app, I can drill into the RadioGroup and make a selection. When I click the back button that I added to the view, the modal view closes and the RadioSelected properted of the ModalRootElement object is set correctly, but the text is not displayed.
If I change Selected() method to call dvc.ActivateController instead of PresentViewController, the ModalRootElement displays the correct text, but the RadioGroup table has the wrong size. Is there a way to get the RootElement to display the correct text when you use PresentViewController instead of ActivateController?
I think you need a Root.Reload() call.
I have a vaadin application that redirect after login to a view with header / left menu and a main panel.
how can I set the menu or any link to switch the main panel according to a specific contents
If I click contact It set ContactLayout in the main panel.
PS: I know how to set a menu like in vaadin documentation but I want to know what to set as command for the menu item.
thanks
I suggest you to keep a Map<MenuItem,AbstractLayout> and when a MenuItem is clicked, remove all the components of your Panel, and add the layout get from the Map.
Visually :
public class TestApplication extends Application {
private VerticalLayout contactLayout;
private Panel mainPanel;
Map<MenuItem, AbstractLayout> swapContentMap;
#Override
public void init() {
Window mainWindow = new Window("Test Application");
mainPanel = new Panel("Main Panel");
mainWindow.addComponent(mainPanel);
// Create all of your layout
// For now, I just create a fake contact layout
contactLayout = new VerticalLayout();
// Here add your default layout to the right panel
mainPanel.addComponent(contactLayout);
Command myCommand = new MyCommand();
MenuBar menuBar = new MenuBar();
MenuItem menuItem = menuBar.addItem("Contact", myCommand);
//add your other menu item
swapContentMap = new HashMap<MenuBar.MenuItem, AbstractLayout>();
swapContentMap.put(menuItem, contactLayout);
//add your other menu item to the map.
setMainWindow(mainWindow);
}
private class MyCommand implements Command
{
public void menuSelected(MenuItem selectedItem)
{
TestApplication.this.mainPanel.removeAllComponents();
TestApplication.this.mainPanel.addComponent(swapContentMap.get(selectedItem));
}
}
}
Hope it will work.
Regards
Éric