how can i create custom controlls with UWP?

민석 전 61 Reputation points
2021-01-20T04:14:03.117+00:00

58330-question.png

When I searched Google for custom controls, I could only find a way to extend the existing controls.

However, I want to know how to make a control from scratch like the attached picture.

Specifically, I want to make the shape of the tree over there so that I can move the circle like Progress bar and register the writing.

Can i create a new control by adding detailed functions like this?

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Answer accepted by question author
  1. AryaDing-MSFT 2,916 Reputation points
    2021-01-20T10:00:32.087+00:00

    Hi,

    Welcome to Microsoft Q&A!

    A custom control is based on an existing control combination. You design new styles and write logic codes for it.

    A custom (templated) control allows an app to use the Template property to replace the control’s internal element tree. If you don’t need your control to have that re-templating feature, it is easier to use UserControl.

    I suggest using UserControl to achieve it, there is a simple sample to use UserControl.

    MyUserControl1.xaml:

    <UserControl  
      ….>  
       <UserControl.Resources>  
            <Style TargetType="TextBox" x:Key="Textboxstyle">  
                <Setter Property="FontStyle" Value="Italic"/>  
                <Setter Property="Width" Value="100"/>  
                <Setter Property="Height" Value="40"/>  
                <Setter Property="VerticalAlignment" Value="Center"/>  
                <Setter Property="HorizontalAlignment" Value="Center"/>  
            </Style>  
        </UserControl.Resources>  
        <Grid>  
            <!--place your control-->  
            <TextBox Style="{StaticResource Textboxstyle}" Text="Hi"/>  
        </Grid>  
    </UserControl>  
    

    MainPage.xaml:

    <Page  …>  
        <Grid><local:MyUserControl1/></Grid>  
    </Page>  
    

    More info can be found here.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.