MonoTouch.Dialog: Sub Section BackgroundView? - xamarin.ios

I have a RootElement with Sections. One section has RadioElements. How do I change the BackgroundView on the sub section?
Something like this doesn't work because the sub view isn't yet created.:
rootGroups = new RootElement ("Ideas", rdoGroup) {
new RootElement ("Baha'i") {
new Section (){
new RadioElement ("Peace"),
new RadioElement ("Unity"),
new RadioElement ("Science")
}
}
};
???
rootGroups.TableView.BackgroundColor = ...;

If you want to create two different view with two different background you must create another dialogViewController for the second root, that way you will be able to change the background.
To do this, instead of using a regular RootElement constructor, use the RootElement constructor that takes a delegate method that can create the UIViewController on demand.

Related

Xamarin TableViewCell select one

I am trying to make table view cell as follows using Xamarin Studio.
public enum Category
{
Travel,
Lodging,
Books
}
I am using Monotouch.Dialog, but cannot find any element.
Any advice?
I guess what you're looking for is the RadioElement of MonoTouch.Dialog. You can see an example in section 3.1 in the MonoTouch.Dialog introduction.
From the example in the doc:
var root = new RootElement ("Meals") {
new Section ("Dinner"){
new RootElement ("Dessert", new RadioGroup ("dessert", 2)) {
new Section () {
new RadioElement ("Ice Cream", "dessert"),
new RadioElement ("Milkshake", "dessert"),
new RadioElement ("Chocolate Cake", "dessert")
}
}
}
}
With this example, you'll have a dialog with one root element called Meals. When tapping this item, you will be presented a new dialog where you can select one of the RadioElements. You create a RadioGroup for the elements that belong together, and the RootElement from which you launch the RadioGroup will show the currently selected value. There's more information about this in section 4.8. of the provided link as well.

Monotouch.Dialog RootElement that opens a UIViewController and Passing in Data

Is there a proper way to use Monotouch.Dialog (iOs) and call a UIViewController when a user clicks on a RootElement? I'm building a page of data based on an array and when clicked I'd like to open this custom view and pass in the array element.. Something like this (doesn't work). Any help is appreciated.
RootElement CreateMenuCategory(JToken menucat) {
RootElement MenuCategory = new RootElement(menucat["menucategoryname"].Value<String>());
RootElement root_element;
Section section = new Section();
foreach(JToken menuitem in menucat["menuitems"]) {
root_element = new RootElement(menuitem["menuitemname"].Value<String>(), (RootElement e) => {
return _menuitemView.LoadMenuItem(menuitem); // menuitem on view is always the same
});
section.Add (root_element);
}
MenuCategory.Add (section);
return MenuCategory;
}
That code doesn't work as the delegate always passes in the same element every time.
This is merely a side effect of how the "menuitem" variable is captured by the lambda function.
Change your foreach loop to look like this instead:
foreach (JToken iteratorMenuitem in menucat ["menuitems"]){
var menuitem = iteratorMenuitem;
//.. the rest

vaadin submenu code for views

Hi i m added the File menu item creating the views, my code look like
final Class viewClass : new Class[] { Dashboard.class,
Editor.class, Ticket.class, MockupView.class }) {
navigator.addView(viewClass.getSimpleName(), viewClass);
menu.addItem(viewClass.getSimpleName(), new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
navigator.navigateTo(viewClass);
}
});
but how to add sub menu item inside this menu, any one can help me if you provide me example it will be great full for me
menu.addItem returns a reference to the new menu item, which you can then use to add child items:
MenuBar.MenuItem item = menu.addItem("Parent", null);
item.addItem("Child", null);
Everything you need to know is on this Vaadin documentation page

In monotouch.dialog can RootElement be easily styled?

Are there any existing extensions or is it fairly straight forward to add styles to RootElement in monotouch.dialog in a similar way you can style StyledStringElement.
Basically I would like to add an image, or badge to RootElement to indicate what sort of details would be in the child view, eg add Success, Warning, Error, Info type image - so the users may only be interested in clicking through to details that are not fully successful.
So ideally I would be able to code something like this...
UIImage imageSuccess = ImageLoader.DefaultRequestImage (new Uri ("file://" + Path.GetFullPath ("Images/Success.png")), null);
var root = new RootElement("Root") {
Image = imageSuccess,
Accessory = UITableViewCellAccessory.DetailDisclosureButton,
new Section (){
new BooleanElement ("Airplane Mode", false),
new RootElement ("Notifications") {
new Section (null, "Turn off Notifications")
{
new BooleanElement ("Notifications", false)
}
}}
};
Thanks for any help or pointers.
This question is old, but if anyone else comes across it you can subclass the RootElement class to add an icon. My code is as follows:
public class ImageRootElement : RootElement
{
private UIImage _image;
public override MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv)
{
var baseCell = base.GetCell (tv);
var cell = new UITableViewCell (UITableViewCellStyle.Subtitle, "cellId");
cell.TextLabel.Text = Caption;
cell.Accessory = baseCell.Accessory;
cell.ImageView.Image = _image;
return cell;
}
public ImageRootElement (string caption, UIImage image) : base(caption)
{
_image = image;
}
}
Since MT.Dialog is open source, you can modify the RootElement properties and constructors however you like. I don't think there's anything that does what you want right out of the box, so you'll have to extend Dialog to meet your needs.
As an aside, it sounds like you MAY be misunderstanding the intent of RootElement. RootElement is simply the main container that all of your sections and elements are in. It doesn't seem to make sense to have a disclosure indicator or badge on a RootElement, simply because that is not the intent of RootElement. It's possible that I could just be misunderstanding you. If, however, you want to do custom styling with badges, etc, on an element, you can create custom element classes that inherit from OwnerDrawnElement, overriding it's two abstract methods. However, read Miguel's answer to a similar question here before doing so.

MonoTouch.Dialog: Title Bar color with reflection api

I'm using the MonoTouch.Dialog reflection API to create a new DialogViewController:
var dashBoard = new RootElement (""){
new Section("My Dashboard", "All alerts, follow-ups, and tasks are automatically synced each time you launch the app") {
new StringElement ("Alerts"),
new StringElement ("Follow-ups"),
new StringElement ("Tasks")
}
};
var dvc = new DialogViewController (dashBoard) {
Autorotate = true
};
navigation.PushViewController (dvc, true);
If I supply the RootElement with a string value I get a nice title bar with text. I want to control the color of that title bar. I'm not seeing any properties that allow me to do this. Do I need to subclass DialogViewController and build my own title bar?
For me, the easiest way to do this is indeed subclassing the DialogViewController, like this:
public class CustomDialogViewController : DialogViewController {
// add constructors here as necessary, dont forget to call base()
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB(0, 115, 176);
}
}

Resources