windows runtime - Change data template when the user selects it -


i have 2 datatemplates. 1 default , other 1 when user selects item. need give selected item double width , height of normal template. how can this?

what want not difficult, not solved swapping data template. instead, accomplished using visual states in xaml. visual state allows create multiple "views" of xaml (for example, looks when selected , when not selected) , switch between easily. swapping data templates big deal, mostafa, , can result in ui flickering because underlying subsystem has re-render many parts of visual tree.

if want learn more visual states, might read on blog article wrote on same subject.

http://blog.jerrynixon.com/2013/11/windows-81-how-to-use-visual-states-in.html

the problem figure out how trigger visual state when item in gridview or listview selected. first, should know isselected property on gridviewitem or listviewitem control houses item. however, it's tricky reach property , common approach sub-class gridview/listview , override preparecontainerforitemoverride , set binding in code-behind.

like this:

class mymodel {     public bool isselected { get; set; } }  class mylist : windows.ui.xaml.controls.listview {     protected override void preparecontainerforitemoverride(dependencyobject element, object item)     {         var model = item mymodel;         var listviewitem = element windows.ui.xaml.controls.listviewitem;          var binding = new windows.ui.xaml.data.binding         {             source = model,             mode = windows.ui.xaml.data.bindingmode.twoway,             path = new propertypath(nameof(model.isselected)),         };         listviewitem.setbinding(windows.ui.xaml.controls.listviewitem.isselectedproperty, binding);         base.preparecontainerforitemoverride(element, item);     } } 

i hope helps.

best of luck!


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -