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