With a breakpoint on the “if” line of this code:
if ((ckbx.Content != null) && (!ckbx.Content.ToString().Contains("(Empty list)")))
{
string groupName = ckbx.Content.ToString();
var contextMenu = new PopupMenu();
contextMenu.Commands.Add(new UICommand("Edit this Group", contextMenuCmd => Frame.Navigate
(typeof(LocationGroupCreator), groupName)));
contextMenu.Commands.Add(new UICommand("Delete this Group", async (contextMenuCmd) =>
{
await SQLiteUtils.DeleteGroupAsync(groupName);
}));
await contextMenu.ShowAsync(args.GetPosition(this));
}
…ckbx.Content is “(Empty list)”, but the condition is seen as false – the condition fails. Why?
Your condition has the logical negation operator (
!) negating the results ofContains:As such, if the content contains “(Empty list)”,
Containswill returntrue, and the!will make itfalse, which makes the condition fail.