#

 

 

 

Der folgende Code ist zum Aufbau eines eigenen Textbox-Kombinations-Elementes, mit welchem man Texte auswählen kann oder manuell eingeben kann

Man muss nur im Projekt einen Unterverzeichnis Usercontrols erstellen, ein neues Usercontrol erstellen und den folgenden Code dort einfügen.

 

XAML Code

 

Im Usercontrol befindet sich nur ein Textbox Element und ein Dropdown Element.

Der Frontend XAML Code

UcSelectionbox.xaml

<UserControl

    x:Class="Rename_Images_Videos_Folder.UserControls.UcSelectionbox"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="using:Rename_Images_Videos_Folder.UserControls"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="40"

    d:DesignWidth="400">

 

    <Grid>

        <TextBox  x:Name="ctlTextbox" Grid.Column="1"   Margin="0,0,29,0" 

                  VerticalAlignment="Stretch"   VerticalContentAlignment="Center" HorizontalAlignment="Stretch" 

                  KeyDown="ctlTextbox_KeyDown"

                  >

        </TextBox>

        <ComboBox Name="ctlDropDown" HorizontalAlignment="Right"  VerticalAlignment="Stretch" Width="30" MinWidth="30"

                DropDownClosed="ctlDropDown_DropDownClosed">

        </ComboBox>

    </Grid>

</UserControl>

 

 

Der zugehörende C# Code der Codebehind Datei

UcSelectionbox.xaml.cs

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Runtime.InteropServices.WindowsRuntime;

using Windows.Foundation;

using Windows.Foundation.Collections;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Controls.Primitives;

using Windows.UI.Xaml.Data;

using Windows.UI.Xaml.Input;

using Windows.UI.Xaml.Media;

using Windows.UI.Xaml.Navigation;

 

 

namespace Rename_Images_Videos_Folder.UserControls

{

    public sealed partial class UcSelectionbox : UserControl

    {

        #region Usercontrol

        //---------------------< region: Usercontrol >----------------------

        public UcSelectionbox()

        {

            this.InitializeComponent();

        }

        //---------------------</ region: Usercontrol >----------------------

        #endregion /Usercontrol

 

        #region Properties

        //---------------------< region: Properties >----------------------

        public String Text {

            get { return  ctlTextbox.Text; }

            set { ctlTextbox.Text =value ; }

        }

 

        public String SelectedText

        {

            get { return ctlDropDown.SelectedItem.ToString(); }

            set { ctlDropDown.SelectedValue= value; }

        }

        //---------------------</ region: Properties >----------------------

        #endregion /Properties

 

 

        #region Controls

        //---------------------< region: Controls >----------------------

        private void ctlDropDown_DropDownClosed(object sender, object e)

        {

            String selectedText = ctlDropDown.SelectedItem as String;

            if (selectedText == null) return;

 

            ctlTextbox.Text = selectedText;

            DataContext = selectedText;

        }

        private void ctlTextbox_KeyDown(object sender, KeyRoutedEventArgs e)

        {

            if (e.Key == Windows.System.VirtualKey.Enter)

            {

                DataContext = ctlTextbox.Text;

            }

        }

        //---------------------</ region: Controls >----------------------

        #endregion /Controls

 

 

        #region Public Methods

        //---------------------< region: Public Methods >----------------------

        public void fill_Seletionbox_by_List(List<String> list_Selections)

        {

            //--< Load Selectionbox >--

            ctlDropDown.Items.Clear();

 

 

            list_Selections.Sort();

            for (int i = 0; i < list_Selections.Count; i++)

            {

                String sText = list_Selections[i];

                add_Text_To_Selection(sText);

            }

            //--</ Load Selectionbox >--

        }

        public void add_Text_To_Selection(String sText)

        {

            ctlDropDown.Items.Add(sText);

        }

       

        //---------------------</ region: Public Methods >----------------------

        #endregion /Public Methods

 

 

    }

}

 

 

 

DropDown, Selection, Selectionbox, Kombinationsfeld

 

Mobile

.