ComponentOne Basic Library for UWP
Basic Library Overview / DropDown for UWP / DropDown for UWP Task-Based Help / Creating a DropDown
In This Topic
    Creating a DropDown
    In This Topic

    You can easily create a C1DropDown control at design time in XAML and in code.  Note that if you create a C1DropDown control as in the following steps, it will appear empty. You will need to add items to the control. For an example, see Adding Content to C1DropDown.

    In XAML

    To create a C1DropDown control using XAML markup, complete the following steps:

    1. In the Visual Studio Solution Explorer, right-click the References folder in the project files list. In the context menu choose Add Reference, select the C1.UWP.dll assembly, and click OK.
    2. Add a XAML namespace to your project by adding xmlns:Xaml="using:C1.Xaml" to the initial <Page> tag. It will appear similar to the following:
    Markup
    Copy Code
    <Page xmlns:Xaml="using:C1.Xaml"
        x:Class="DropDownTest.MainPage"
        xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:DropDownTest"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
    1. Set the name of Grid to LayoutRoot and add a <Xaml:C1DropDown> tag to your project within the <Grid> tag to create a C1DropDown control. The markup will appear similar to the following:
    Markup
    Copy Code
    <Grid x:Name="LayoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
         <Xaml:C1DropDown Name="c1dropdown1" />     
    </Grid>
    

    This markup will create an empty C1DropDown control named "c1dropdown1" and set the control's size.

     

    In Code

    To create a C1DropDown control in code, complete the following steps:

    1. In the Visual Studio Solution Explorer, right-click the References folder in the project files list. In the context menu choose Add Reference, select the C1.Xaml.dll assembly, and click OK.
    1. Right-click within the MainPage.xaml window and select View Code to switch to Code view
    1. Add the following import statement to the top of the page:
    C#
    Copy Code
    using C1.Xaml;
    
    1. Add code to the page's constructor to create the C1DropDown control. It will look similar to the following:
    C#
    Copy Code
    C1DropDown c1dropdown1 = new C1DropDown();
    c1dropdown1.Height = 30;
    c1dropdown1.Width = 100;
    LayoutRoot.Children.Add(c1dropdown1);
    

    This code will create an empty C1DropDown control named "c1dropdown1", set the control's size, and add the control to the page.

     

     What You've Accomplished

    You've created a C1DropDown control. Note that when you create a C1DropDown control as in the above steps, it will appear empty. You can add items to the control that can be interacted with at run time. For an example, see Adding Content to C1DropDown.

    See Also