Так у меня есть этот класс:ListView с DataTemplate - java.lang.reflect.InvocationTargetException
public class MenuItem
{
public string image { private set; get; }
public string text { private set; get; }
public MenuItem (string image, string text)
{
this.image = image;
this.text = text;
}
}
И следующий класс ViewCell:
public class MenuItemCell : ViewCell
{
public MenuItemCell()
{
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(100, GridUnitType.Auto) },
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(50, GridUnitType.Auto) },
new ColumnDefinition { Width = new GridLength(100, GridUnitType.Auto) },
}
};
var menuImage = new Image
{
IsVisible = true,
Aspect = Aspect.AspectFit,
};
var text = new Label {
TextColor = Color.Yellow,
BackgroundColor = Color.White,
};
menuImage.SetBinding (ImageCell.ImageSourceProperty, "image");
text.SetBinding (Label.TextProperty, "text");
grid.Children.Add (menuImage, 0, 1, 0, 1);
grid.Children.Add (text, 1, 2, 0, 1);
this.View = grid;
}
страница содержание заключается в следующем:
public class Navigation : ContentPage
{
ListView menu;
ProfileView profile;
DataTemplate viewTemplate;
List<MenuItem> items;
public Navigation()
{
profile = new ProfileView();
items = new List<MenuItem> {
new MenuItem ("menuTradeIconBig.png", "TRADE"),
new MenuItem ("menuProfileIconBig.png", "PROFILE"),
new MenuItem ("menuPositionsIconBig.png", "POSITIONS"),
};
menu = new ListView { RowHeight = 40 };
menu.Header = profile;
var viewTemplate = new DataTemplate (typeof(MenuItemCell));
menu.ItemTemplate = viewTemplate;
menu.ItemsSource = items;
Content = new StackLayout {
Children = {
menu
}
};
}
Проблема в том, что когда я нажимаю кнопку, которая отвечает за открытие страницы содержимого, я получаю
java.lang.reflect.InvocationTargetException
Если я Закомментируйте menu.ItemTemplate = viewTemplate;
, страница загружается, но в списке все элементы имеют текст MyProjectName.MenuItem
.
Я попытался ваше предложение, но он по-прежнему падает с той же ошибкой. Я даже удалил заголовок целиком только для тестирования, и он по-прежнему падает. Я посмотрю в HeaderTemplate, но проблемы там нет. –
делитесь более полной трассой –