I get two errors if I click on the navigation menu during runtime? I am a beginner in C# and have no idea how to solve this problem.
var group = (SampleDataGroup)e.ClickedItem;
var groupId = group.UniqueId;
var item = (SampleDataItem)e.ClickedItem;
var itemId = item.UniqueId;
InvalidCastException:
In System.InvalidCastException ist eine Ausnahme vom Typ "AstroApp.exe" aufgetreten, doch wurde diese im Benutzercode nicht verarbeitet.
Zusätzliche Informationen: Das Objekt des Typs "AstroApp.Data.SampleDataItem" kann nicht in Typ "AstroApp.Data.SampleDataGroup" umgewandelt werden.
public class SampleDataItem : SampleDataGroup
{
// add flag as last param
public SampleDataItem(String uniqueId, String title, String subtitle,
String imagePath, String description, String content, SampleDataGroup group, int intIsCustomNav): base(uniqueId, title, subtitle, imagePath, description)
{
this._content = content;
this._group = group;
this.intIsCustomNav = intIsCustomNav;
}
private string _content = string.Empty;
public string Content
{
get { return this._content; }
set { this.SetProperty(ref this._content,value);}
}
private void SetProperty(ref string p, string value)
{
throw new NotImplementedException();
}
private SampleDataGroup _group;
public SampleDataGroup Group
{
get { return this._group; }
set { this.SetProperty(ref this._group,value);}
}
private void SetProperty(ref SampleDataGroup sampleDataGroup, SampleDataGroup value)
{
throw new NotImplementedException();
}
public int intIsCustomNav { get; set; }
}
/// <summary>
/// Wird aufgerufen, wenn auf ein Element innerhalb einer Gruppe geklickt wird.
/// </summary>
/// <param name="sender">GridView (oder ListView, wenn die Anwendung angedockt ist),
/// die das angeklickte Element anzeigt.</param>
/// <param name="e">Ereignisdaten, die das angeklickte Element beschreiben.</param>
void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
// Navigate to the appropriate destination page, configuring the new page
// by passing required information as a navigation parameter
var group = (SampleDataGroup)e.ClickedItem;
var groupId = group.UniqueId;
var item = (SampleDataItem)e.ClickedItem;
var itemId = item.UniqueId;
int intGroup = Convert.ToInt32(group);
// Abfrage Gruppe 1
if (intGroup == 0)
// Abfrage der Seiten
if (item.intIsCustomNav == 0)
{
// Gruppe 1, Seite 1
this.Frame.Navigate(typeof(ItemDetailPage), itemId);
}
if (item.intIsCustomNav == 1)
{
// Gruppe 1, Seite 2
this.Frame.Navigate(typeof(ItemDetailPageA2), itemId);
}
// Abfrage Gruppe 2
if (intGroup == 1)
{
// Abfrage der Seiten
if (item.intIsCustomNav == 0)
{
// Gruppe 2, Seite 1
this.Frame.Navigate(typeof(ItemDetailPageB1), itemId);
}
}
}