Section.HeaderView is resizing automatically in Monotouch Dialog - xamarin.ios

I'm using Monotouch.Dialog and
I have subclassed the class Section to implement a custom HeaderView. The problem is that the header view is automatically resized, here's the code I'm using :
public class MySection : Section
{
public MySection ()
{
UIView v = new UIView(new RectangleF(0,0,30,30));
v.BackgroundColor = UIColor.Red;
this.HeaderView = v;
}
}
I've attached the screen shot :
http://imageshack.us/photo/my-images/864/capturedcran20120508212.png
EDIT
Ok I've kind of find the way to resolve this
The trick is to add a View that will contain your real HeaderView and sets the AutosizesSubviews property to false. Then just add the view to the latest :
public class MySection : Section
{
public MySection ()
{
UIView v0 = new UIView(new RectangleF(0,0,50, 60));
v0.AutosizesSubviews = false;
UIView v = new UIView(new RectangleF(0,0,30,30));
v.BackgroundColor = UIColor.Red;
v0.AddSubview(v);
this.HeaderView = v0;
}
}

Related

Set Title in View in mvvmcross 5.1

Good afternoon.
I was using Xamarin and MVVMCROSS version 5.0 to create multiple tabs and navigate them between them.
In my code i have a Root page that directs to the pages:
[MvxRootPresentation(WrapInNavigationController = true)]
public sealed partial class RootView : MvxTabBarViewController<RootViewModel>
{
private bool _isPresentedFirstTime = true;
public RootView()
{
// ViewDidLoad();
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (ViewModel != null && _isPresentedFirstTime)
{
_isPresentedFirstTime = false;
ViewModel.ShowInitialViewModels();
}
//Alterando o BackGround da tabBar
this.TabBar.BarTintColor = UIColor.FromRGBA(237, 146, 4, 1);
this.TabBar.Translucent = false;
//this.TabBar.Opaque = false;
//Cor do ícone antes de selecionado
this.TabBar.UnselectedItemTintColor = UIColor.White;
//Cor do ícone após seleção
this.TabBar.SelectedImageTintColor = UIColor.Black;
//Setando imagem antes e depois da seleção
this.TabBar.Items[4].Image = UIImage.FromBundle("valdemarMenuBar.png").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
this.TabBar.Items[4].SelectedImage = UIImage.FromBundle("valdemarMenuBar.png").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}
...
In each of the Views I set the Titles of the navigations bars according to the example below:
[MvxTabPresentation(WrapInNavigationController = true, TabIconName = "newOrder", TabName = "Novo Pedido")]
public partial class NewOrder2ViewController : BaseScrollViewController
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (ViewModel == null)
{
return;
}
Title = "Novo Pedido";
...
When I upgraded to version 5.1.1 of MVVMCROSS this functionality has stopped.
Can anyone help me about what happened.
I did not find anything in the documentation for this new version of MVVMCROSS.
Thank you very much in advance.
You're seeing this strange behavior because you have two UINavigationControllers ovelapped on each tab, one over the other (this is because your TabBarViewController is wrapped in a navigation controller).
In order to fix it, you just need to change the value of the attribute property:
[MvxRootPresentation(WrapInNavigationController = false)]
public sealed partial class RootView : MvxTabBarViewController<RootViewModel>
{
//...
}

How to bind Map/Image in a List with Click event?

I want to bind map with a field and its click event as well, which will take it to a MvxCommand and show some MapViewModel.
[Register("HoursEntryCell")]
public class HoursEntryCell : MvxTableViewCell
{
public HoursEntryCell()
{
CreateLayout();
InitializeBindings();
}
public HoursEntryCell(IntPtr handle)
: base(handle)
{
CreateLayout();
InitializeBindings();
}
private UILabel hours;
private UIImageView imageView;
private UILabel jobName;
private MKMapView location;
private void CreateLayout()
{
jobName = new UILabel(new RectangleF(10, 10, 100, 30));
jobName.AdjustsFontSizeToFitWidth = true;
jobName.Lines = 0;
jobName.Font = jobName.Font.WithSize(16);
imageView = new UIImageView(UIImage.FromBundle("pencil.png"));
imageView.Frame = new RectangleF(270, 10,imageView.Image.CGImage.Width, imageView.Image.CGImage.Height);
Accessory = UITableViewCellAccessory.DisclosureIndicator;
location = new MKMapView(new RectangleF(15, 40, 280, 160));
location.AddAnnotation(new MKPointAnnotation()
{
Title = "My Loc",
Coordinate = new CLLocationCoordinate2D(23.0092509, 72.5061084)
});
location.UserInteractionEnabled = false;
salaryLable.Text = "Salary";
hours = new UILabel(new RectangleF(200,200,50,50));
ContentView.AddSubviews(jobName, location, hours,salaryLable, imageView);
}
private void InitializeBindings()
{
this.DelayBind(() =>
{
var set = this.CreateBindingSet<HoursEntryCell, ListViewModel>();
set.Bind(location).To(vm => vm.MyLocation);
set.Bind(hours).To(vm => vm.Salary);
set.Bind(jobName).To(vm => vm.EmployeeName);
set.Apply();
});
}
}
}
I want to achieve something like set.Bind(location).To(vm => vm.GoNextCommand); along with the map (set.Bind(location).To(vm => vm.MyLocation);)
Or How can I bind simple image button click event to a MvxCommand from the list?
How can I go for it?
Need Help.
You'll probably need to do a combination of things to get this to work properly...
1.) Do your binding from the view that has your list view. In the example above how does the cell actually get access to your view model? Look at the example here: https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/DailyDilbert/DailyDilbert.Touch/Views/ListView.cs#L16
2.) you'll need to probably create custom bindings to handle the map view or it might be similar to this example from Stuart: MvvmCross iOS: How to bind MapView Annotation to jump to another view?

Converting ToolBar to ToolStrip control and MouseHover not working

I have a large winform application which we working to modify the appearance. I am replacing System.Windows.Forms.Toolbar to System.Windows.Forms.ToolStrip control. I use a custom renderer to change dropdown arrow color. with default renderer i get mouse hover effects in toolstrip but with my custom rendering it dont seem to work. Here's my code.
Tool strip initialization:I removed unnecessary code for reading comfort
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
this.toolStrip1.ImageList = this.imageList1;
this.toolStrip1.ImageScalingSize = new System.Drawing.Size(55, 32);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripDropDownButton1
});
this.toolStrip1.Renderer = new MyRenderer();
Toolstrip dropdown button:
this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripDropDownButton1.ImageIndex = 0;
this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
CustomRenderer
public class MyRenderer : ToolStripRenderer
{
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
e.ArrowColor = Color.White;
base.OnRenderArrow(e);
}
}
thanks to #LarsTech for his help. I found this working. I made this below modification in renderer and in code.
Added this line in initialization
this.Toolstip1.RenderMode = ToolStripRenderMode.Professional;
CustomRenderer
public class MyRenderer : ToolStripProfessionalRenderer //Professional renderer
{
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
{
e.ArrowColor = Color.White;
base.OnRenderArrow(e);
}
}

MonoTouch DialogViewController - why must it be in the first place of a UINavigationController?

I want to use a DialogViewController inside of a UITabViewController.
Problem: Nested elements don't show a navigation bar, and so it is not possible to go back.
When I push my class (inherited from DialogViewController) to a UINavigationController, then the behavior is correct. If I use the same class in a tab of a UITabViewController (even with an underlying UINavigationController), then the behaviour is wrong.
Can anyone help me out?
Although the question is not assisted with some code sample, I made a small example hoping to solve your question. For this example I used the Tabbed Application template which comes with Xamarin.iOS and named it TabbingTest.
The following code goes in the AppDelegate. Change the FinishedLaunching method to contain:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
var viewControllers = new UIViewController[]
{
CreateTabFor("Test", "first", new TestDialogController ()),
CreateTabFor("Second", "second", new SecondViewController ()),
};
tabBarController = new UITabBarController ();
tabBarController.ViewControllers = viewControllers;
tabBarController.SelectedViewController = tabBarController.ViewControllers[0];
window.RootViewController = tabBarController;
window.MakeKeyAndVisible ();
return true;
}
Then add the following methods:
private int _createdSoFarCount = 0;
private UIViewController CreateTabFor(string title, string imageName, UIViewController view)
{
var controller = new UINavigationController();
controller.NavigationBar.TintColor = UIColor.Black;
var screen = view;
SetTitleAndTabBarItem(screen, title, imageName);
controller.PushViewController(screen, false);
return controller;
}
private void SetTitleAndTabBarItem(UIViewController screen, string title, string imageName)
{
screen.Title = NSBundle.MainBundle.LocalizedString (title, title);
screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle(imageName),
_createdSoFarCount);
_createdSoFarCount++;
}
Create a class named TestDialogController and paste the following code inside.
using System;
using MonoTouch.Dialog;
using MonoTouch.UIKit;
namespace TabbingTest
{
public class TestDialogController : DialogViewController
{
public TestDialogController (): base(UITableViewStyle.Plain,null,false)
{
var root = new RootElement ("Tabbing test"){
new Section (){
new RootElement ("First level", 0, 0) {
new Section (null, "This is the first level."){
new RootElement ("Second level", 0, 0) {
new Section (null, "This is the second level."){
new BooleanElement ("Flipflops", false)
}
}
}
}}
};
this.Root = root;
}
}
}
Now run the application.
You can see that even the nested elements show up nicely in the navigation bar. Even with multilevel nesting.

Monotouch Dialog Custom Element and GetHeight not being called

Using Monotouch 5.2.11 iOS
I have followed this tutorial (http://tirania.org/monomac/archive/2011/Jan-18.html), created a custom cell with an image and have also added the IElementSizing Interface. The GetHeight is never called.
Similar questions have been asked and the generally accepted solution was to make sure and create the RootElements first, set the UnEvenRows=true before adding them to the Controller. This did not work. I've tried that as well as about every other combination of adding sections to root elements and have not ever seen the GetHeight fired.
The MyDataElement is an image that is 320x200 which displays fine, but the string element that comes after it is not shown (assuming it is behind it). Consequently if I drag the custom cell up above the top, it disappears, reappears, and the second stringelement displays on top of it.
Here is the code I've tried:
public class MyDataElement : Element, IElementSizing {
static NSString key = new NSString ("myDataElement");
public MyData MyData;
public MyDataElement (MyData myData) : base (null)
{
MyData = myData;
}
public float GetHeight (UITableView tableView, NSIndexPath indexPath){
return 200f; // break point here is never hit ever
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell (key) as MyDataCell;
if (cell == null)
cell = new MyDataCell (MyData, key);
else
cell.UpdateCell (MyData);
return cell;
}
public partial class TableTester : DialogViewController
{
public TableTester () : base (UITableViewStyle.Grouped, null)
{
var re = new RootElement("Sample") {
new Section("Testy") {
new MyDataElement(new MyData() { stuff="hello"}),
new StringElement("Sample")
}
};
re.UnevenRows = true;
this.Root = re;
//this.Root = root;
}
}
In addition to that I've even done this which didn't work either:
public class TestNavigator : UINavigationController {
public TestNavigator() {
TabBarItem = new UITabBarItem("Test", null, 1);
var re = new RootElement("Sample") {
new Section("Sammy") {
new StringElement("Sample"),
new MyDataElement(new MyData() { stuff="sam"}),
new StringElement("Sample 2")
}
};
re.UnevenRows = true;
var dv = new DialogViewController(re);
re.UnevenRows = true;
PushViewController(dv, true);
}
After plenty of trial and error, I had to make sure and remove the reference to Monotouch.Dialog that I had downloaded from github and use the built in reference. It seems that the getheight maybe broken in github.

Resources