Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

ComboBoxItem in UWP WPF hinzufügen

01.11.2019 (👁7711)

Wert in einer ComboBox ComboboxItem setzen

Dieses Beispiel zeigt wie man einen Eintag in einem Auswahlfeld / ComboBox in UWP und WPF per XAML und per Code erstellen kann

UWP, WPF, Select Feld Dropdown Auswahl

In XAML

Man setzt in die ComboBox innerhalb mehrere ComboBoxItems

<ComboBox Grid.Row="1" Grid.Column="1" x:Name="CameraNr"  Width="200" HorizontalAlignment="Left" VerticalAlignment="Stretch"  VerticalContentAlignment="Center"  

                      SelectedIndex="1" >

                <ComboBoxItem HorizontalContentAlignment="Center" Tag="1" Content="Camera1"></ComboBoxItem>

                <ComboBoxItem HorizontalContentAlignment="Center" Tag="2" Content="Camera2"></ComboBoxItem>

            </ComboBox>

Setzen im Code

C#

Im C# Code fügt man die ComboBoxItem hinzu, indem man diese zur Laufzeit mit new ComboBoxItem() erstellt und dann .Content=“abc“ und .Tag=“Nr1“ zuweist

private async Task<bool> Init_List_Cameras()

        {

            //----< @Loop: all Cameras >----

            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            for(int iDevice=0;iDevice<allVideoDevices.Count;iDevice++)

            {

                //< add comboBoxItem >

                DeviceInformation camera = allVideoDevices[iDevice];

                string sCameraName = camera.Name;

                ComboBoxItem itemCamera = new ComboBoxItem();

                itemCamera.Content = sCameraName;

                itemCamera.Tag="1";

                CameraNr.Items.Add(itemCamera);

                //</ add comboBoxItem >

            }

            //----</ @Loop: all Cameras >----

            //int Set_CameraNr = Convert.ToInt32(ApplicationData.Current.LocalSettings.Values["Set_CameraNr"].ToString());

            return true;

        }