Created
August 4, 2014 17:56
-
-
Save rmarinho/4097a42e3957bdaa9b03 to your computer and use it in GitHub Desktop.
TEmplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GridViewItemCell : UICollectionViewCell | |
{ | |
public const string Key = "GridViewItemCell"; | |
private ViewCell viewCell; | |
private UIView view; | |
public ViewCell ViewCell { | |
get { | |
return this.viewCell; | |
} | |
set { | |
if (this.viewCell == value) { | |
return; | |
} | |
this.UpdateCell (value); | |
} | |
} | |
[Export ("initWithFrame:")] | |
public GridViewItemCell (System.Drawing.RectangleF frame) : base (frame) | |
{ | |
SelectedBackgroundView = new GridItemSelectedViewOverlay (frame); | |
//this.BringSubviewToFront (SelectedBackgroundView); | |
} | |
private void UpdateCell (ViewCell cell) | |
{ | |
if (this.viewCell != null) { | |
//this.viewCell.SendDisappearing (); | |
this.viewCell.PropertyChanged -= new PropertyChangedEventHandler (this.HandlePropertyChanged); | |
} | |
this.viewCell = cell; | |
this.viewCell.PropertyChanged += new PropertyChangedEventHandler (this.HandlePropertyChanged); | |
//this.viewCell.SendAppearing (); | |
this.UpdateView (); | |
} | |
private void HandlePropertyChanged (object sender, PropertyChangedEventArgs e) | |
{ | |
this.UpdateView (); | |
} | |
private void UpdateView () | |
{ | |
if (this.view != null) { | |
this.view.RemoveFromSuperview (); | |
} | |
this.view = RendererFactory.GetRenderer (this.viewCell.View).NativeView; | |
this.AddSubview (this.view); | |
this.BringSubviewToFront (SelectedBackgroundView); | |
} | |
public override void LayoutSubviews () | |
{ | |
base.LayoutSubviews (); | |
RectangleF frame = this.ContentView.Frame; | |
frame.X = (this.Bounds.Width - frame.Width) / 2; | |
frame.Y = (this.Bounds.Height - frame.Height) / 2; | |
this.ViewCell.View.Layout (frame.ToRectangle ()); | |
this.view.Frame = frame; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment