"Win 10 app development" Adaptivetrigger can be triggered in a custom control

Source: Internet
Author: User

A few days ago, saw a netizen to leave a message to me, said Adaptivetrigger in the custom control (templated control) cannot trigger. Because at that time I was writing other code, did not do the experiment to verify, so I gave the netizen to use Gotovisualstate method to switch state.

When I was free today, I did the test and found that the Adaptivetrigger trigger can be triggered in a templated control's widget template.

First, add a new templated control to the application project, which I call mycontrol. Such as.

Then open the Generic.xaml file, find the style of the new control, and modify the template to:

                <ControlTemplateTargetType= "Local:mycontrol">                    <BorderBackground="{TemplateBinding Background}"BorderBrush="{TemplateBinding BorderBrush}"borderthickness="{TemplateBinding BorderThickness}"x:name= "BD">                        <visualstatemanager.visualstategroups>                            <VisualStateGroup>                                <VisualState>                                    <visualstate.statetriggers>                                        <AdaptivetriggerMinwindowwidth= "The " />                                    </visualstate.statetriggers>                                    <visualstate.setters>                                        <SetterTarget= "Bd." Background "Value= "Red" />                                    </visualstate.setters>                                </VisualState>                            </VisualStateGroup>                        </visualstatemanager.visualstategroups>                    </Border>                </ControlTemplate>

The above template has a visualization state applied, and the state is triggered by Adaptivetrigger, which is triggered when the width of the application window is >= 700, changing the background color of border in the template to red.

Then open mainpage and declare a mycontrol instance on the page.

    <Background= "{ThemeResource Applicationpagebackgroundthemebrush} " >        <  />    </Grid>

Finally, run the application with the following effect.

Then, pull the width of the window wide, and you'll see the background turn red.

Through this experiment, I found that theAdaptivetrigger trigger is available in the template of the custom control.

Sample source code Download

"Win 10 app development" Adaptivetrigger can be triggered in a custom control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.