How to Add an Error Message Before Deleting an Item from a ListBox in Windows Phone 8.1

2

Great masters, I am here again in search of knowledge. I have a small application in Windows Phone 8.1, with a SQLite database, according to the screen below:

I would like that when selecting the item in the ListBox, and clicking the Delete button, a message is triggered asking if the user wants to delete this data. The code for the Delete button is as below:

    private async void btnExcluir_Click(object sender, RoutedEventArgs e)
    {
        var excluir = ltbExibir.SelectedItem as Moto;
        excluir.mot_nome = txtNomeMoto.Text;
        excluir.mot_placa = txtPlacaMoto.Text;
        await conexao.DeleteAsync(excluir);            
    }

And taking advantage of the opportunity, I would like to know how to insert title in the columns of the ListBox. I look forward to your valuable information.

    
asked by anonymous 24.11.2015 / 13:07

2 answers

0

To display a dialog box in Windows Phone 8.1 you should use the Windows.UI.Popups.MessageDialog . You can add a title, a message and for Windows Phone 8.1 it allows you to add a maximum of 2 buttons.

Here is an example of usage:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    // Crie uma instância da classe MessageDialog passando a mensagem e o título da mensagem
    MessageDialog msg = new MessageDialog("C# melhor linguagem! Você concorda né?", "Oi oi oi!");

    // Adicione os botões desejados e configure os eventos para cada um
    msg.Commands.Add(new UICommand("Sim", new UICommandInvokedHandler(CommandHandlers)));
    msg.Commands.Add(new UICommand("Não", new UICommandInvokedHandler(CommandHandlers)));

    // Exibe a MessageDialog
    await msg.ShowAsync();
}

public void CommandHandlers(IUICommand commandLabel)
{
    // A verificação de qual botão foi pressionado pelo usuário só pode ser feita dessa forma
    var action = commandLabel.Label;
    switch (action)
    {
        case "Sim":
            // Faça alguma coisa pra alegrar o usuário, ele deu a resposta certa
            break;

        case "Não":
            // Reposta errada, faça alguma outra coisa
            break;
    }
}

As for the multiple columns in ListView , this will only be possible through a custom%% to DataTemplate and the column titles would have to be made out of control. This happens because the ListView.ItemTemplate control was not done to display data in a "table" format.

    
24.11.2015 / 13:49
-1

Silverlight Solution

You should use the MessageBox for this as follows:

MessageBoxResult result = MessageBox.Show("Deseja continuar?", "Opção", MessageBoxButton.OKCancel);

if (result == MessageBoxResult.OK)
{
    //Logica
}

WinRT Solution

MessageDialog msgDialog = new MessageDialog("Sua mensagem", "Titulo");

//OK Button
UICommand okBtn = new UICommand("OK");
okBtn.Invoked = OkBtnClick;
msgDialog.Commands.Add(okBtn);

//Cancel Button
UICommand cancelBtn = new UICommand("Cancel");
cancelBtn.Invoked = CancelBtnClick;
msgDialog.Commands.Add(cancelBtn);

//Show message
msgDialog.ShowAsync();

And create button call methods:

private void CancelBtnClick(IUICommand command)
{
}

private void OkBtnClick(IUICommand command)
{
}
    
24.11.2015 / 13:20