Category:UWP
Article From:https://www.cnblogs.com/hupo376787/p/9121529.html

I’m also talking about the big bang technology that my app [small Natural Language Processing] implements in my app UWP.

 

Look at the effect first.

My control is based on wrappanel, as blue fire says, so it looks neat. He doesn’t like this. But I think it’s OK. Haha

 

The programmer is also very difficult, ha

 

 

The big bang technology is divided into two main parts:

1. Separate words into words.

2. Display, display the word

 

 

1. participle

Xiaowei NLP’s participle technology adopts Boson NLP and Tencent AI dual engine, which can switch freely on the set interface and come into effect in real time.

 

 How to realize encapsulation and invocation is not introduced here. There is a need for private correspondence.

Take Boson NLP as an example, take a look at the data returned from the server and parse it.

        private async Task OnSegTag()
        {
            var resBosonSegTag = await BosonAIHelper.WordSegAndTag(textInput.Text.Trim());
            if (resBosonSegTag != null && resBosonSegTag.tag.Count > 0)
            {
                for (int i = 0; i <= resBosonSegTag.tag.Count - 1; i++)
                {
                    NLPWord nlp = new NLPWord
                    {
                        word = resBosonSegTag.word[i],
                        width = resBosonSegTag.word[i].Length * 20,
                        bgcolor = PosTagHelper.GetPosColor_Boson(resBosonSegTag.tag[i])
                    };
                    SegTagItems.Add(nlp);
                }
            }
        }

 

 That width doesn’t work, and it’s where it is.

word:Words and punctuation, and so on

bgcolor:The background color of each class of words

 

 

 

 

2. display

Because of the use of wrappanel, it is much simpler.

You just need to customize the template.

 

<Page.Resources>
        <DataTemplate x:Key="WordsTemplate">
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{Binding bgcolor}">
                <TextBlock Text="{Binding word}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,6,0,0"/>
            </StackPanel>
        </DataTemplate>
    </Page.Resources>

 

                 <ListView Grid.Row="2"
                    x:Name="WrapPanelContainer"
                    IsItemClickEnabled="True"
                    SelectionMode="Extended"
                    Style="{StaticResource ListViewAppleStyle}"
                    ItemsSource="{x:Bind Mode=OneWay, Path=SegTagItems}"
                    ItemTemplate="{StaticResource WordsTemplate}">
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <controls:WrapPanel />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                            <Setter Property="VerticalContentAlignment" Value="Stretch" />
                            <Setter Property="Height" Value="36" />
                            <Setter Property="MinHeight" Value="36" />
                            <Setter Property="Padding" Value="2"/>
                        </Style>
                    </ListView.ItemContainerStyle>
                </ListView>

 

And then it’s happy to show it

 

 

Link of this Article: UWP big bang, your hammer

Leave a Reply

Your email address will not be published. Required fields are marked *