User Tools

Site Tools


notes:uwp:datatemplate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
notes:uwp:datatemplate [2016/12/21]
admin
notes:uwp:datatemplate [2020/08/26] (current)
Line 193: Line 193:
         }         }
     }     }
 +}
 +</code>
 +
 +
 +Example: Change //DataTemplate// (and //ItemsPanelTemplate//) dynamically in code. We assume appropriate templates are defined in resources. To retrieve templates from application resources use //Application.Current.Resources// rather than //this.Resources//.
 +<code csharp>
 +// viewType is a variable of type enum 
 +switch(viewType)
 +{
 +    case ViewType.Default:
 +        {
 +            DataTemplate defaultTemplate = this.Resources["DefaultDataTemplate"] as DataTemplate;
 +            GridView1.ItemTemplate = defaultTemplate;
 +            GridView1.ItemsPanel = this.Resources["DefaultPanelTemplate"] as ItemsPanelTemplate;
 +        }
 +        break;
 +    case ViewType.Compact:
 +        {
 +            DataTemplate compactTemplate = this.Resources["CompactDataTemplate"] as DataTemplate;
 +            GridView1.ItemTemplate = compactTemplate;
 +            GridView1.ItemsPanel = this.Resources["CompactPanelTemplate"] as ItemsPanelTemplate;
 +        }
 +        break;
 +    case ViewType.Grid:
 +        {
 +            DataTemplate gridTemplate = this.Resources["GridDataTemplate"] as DataTemplate;
 +            GridView1.ItemTemplate = gridTemplate;
 +            GridView1.ItemsPanel = this.Resources["GridPanelTemplate"] as ItemsPanelTemplate;
 +        }
 +        break;
 +    default:
 +        throw new ArgumentException("Unrecognized view type.");
 } }
 </code> </code>
  
notes/uwp/datatemplate.1482360430.txt.gz ยท Last modified: 2020/08/26 (external edit)