Event item Combobox

Asked

Viewed 184 times

1

I have a combobox and would like when I selected the date item to make the datapick visible. How to perform this operation?

1 answer

1


Interpreting "visible datapick" as the selected item, one of the possibilities would be:

XAML

<ComboBox x:Name="ComboBoxOpcoes" SelectionChanged="ComboBoxOpcoes_OnSelectionChanged">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Width="Auto" Height="Auto">
                <TextBlock Text="{Binding Tipo}"/>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

Code

public sealed partial class MainPage
{
    public MainPage()
    {
        InitializeComponent();

        var items = new ObservableCollection<Opcoes>();
        var item = new Opcoes() { Tipo = "Opcao 1" };
        items.Add(new Opcoes() { Tipo = "Opccao 2" });
        items.Add(item);
        items.Add(new Opcoes() { Tipo = "Outra opcao" });

        ComboBoxOpcoes.ItemsSource = items;
        ComboBoxOpcoes.SelectedItem = item;
    }

    private void ComboBoxOpcoes_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var combo = (Windows.UI.Xaml.Controls.ComboBox)sender;
        var item = (Opcoes)combo.SelectedItem;
        Debug.Write($"selecionado: {item?.Tipo}");
    }
}

public class Opcoes
{
    public string Tipo { get; set; }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.