Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Problem with header template while using GroupHeaderTemplate and GroupShortNameBinding.

$
0
0

Look at the first screen shot, it looks perfect

And now after scrolling listview header size becomes uneven and DisclosureIndicator appears on the header template instead on custom cell.

Here is code

----------------------------------------------------------------------------- listview -----------------------------------------------------------------------------

demoList = new ListView {
ItemTemplate = new DataTemplate (typeof(CustomCell)) {
},
IsGroupingEnabled = true,
ItemsSource = items,
};

        demoList.GroupDisplayBinding = new Binding("Title");
        demoList.GroupShortNameBinding = new Binding ("ShortName");
        if(Device.OS != TargetPlatform.WinPhone)
            demoList.GroupHeaderTemplate = new DataTemplate(typeof(GroupHeader));

----------------------------------------------------------------------------- renderer -----------------------------------------------------------------------------

[assembly:ExportCell(typeof(CustomCell), typeof(CustomCellRenderer))]
namespace demo.iOS
{
public class CustomCellRenderer: ViewCellRenderer
{
public override MonoTouch.UIKit.UITableViewCell GetCell(Cell item, MonoTouch.UIKit.UITableView tv)
{
var aspectCell = base.GetCell(item, tv);
aspectCell.Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator;
return aspectCell;
}
}
}

----------------------------------------------------------------------------- CustomCell -----------------------------------------------------------------------------
public class CustomCell : ViewCell
{
public Label titleLabel { get; set;}
public Label detailLabel { get; set;}

    public CustomCell ()
    {

        titleLabel = new Label {
            Font = Font.SystemFontOfSize (NamedSize.Medium),
        };
        titleLabel.SetBinding (Label.TextProperty, "Name");

        detailLabel = new Label {
            Font = Font.SystemFontOfSize (NamedSize.Small),
            TextColor = Color.Gray
        };
        detailLabel.SetBinding (Label.TextProperty, "Place");


        var cellLayout = new StackLayout()
        {

            Orientation = StackOrientation.Vertical,
            VerticalOptions = LayoutOptions.StartAndExpand,
            Padding = new Thickness (5,0,0,0),
            Spacing = 0.0,
            Children = { 
                        titleLabel,detailLabel
            }
        };

        this.View = cellLayout;
    }


    protected override void OnBindingContextChanged ()
    {
        base.OnBindingContextChanged ();
        this.Height = 50;
    }

}

----------------------------------------------------------------------------- GroupHeader -----------------------------------------------------------------------------

public class GroupHeader: ViewCell
{
public GroupHeader()
{
this.Height = 25;
var title = new Label
{
Font = Font.SystemFontOfSize(NamedSize.Small, FontAttributes.Bold),
TextColor = Color.White,
VerticalOptions = LayoutOptions.FillAndExpand
};

        title.SetBinding(Label.TextProperty, "Title");

        View = new StackLayout
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            HeightRequest = 25,
            BackgroundColor = Color.FromRgb(52, 152, 218),
            Padding = 5,
            Orientation = StackOrientation.Horizontal,
            Children = { title }
        };
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles