c# - UWP App using MVVM: Registration of feature view on main view -


i new c# , uwp apps. , first try mvvm. have following program design , go according schema of fdd. mvvm app-design

i achieve:

  • registration of viewfeature.xaml on viewmain.xaml
  • communication between features.

i have following simple approach: add viewfeature.xaml viewmain.xaml code, unfortunately not work @ moment.

  • view registration:

mainview.xaml

<page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodels="using:client.viewmodel" x:class="client.view.viewmain" mc:ignorable="d">  <grid x:name="contentgrid" requestedtheme="light">     <grid.columndefinitions>         <columndefinition width="auto"/>         <columndefinition width="auto"/>         <columndefinition width="auto"/>     </grid.columndefinitions>     <stackpanel name="featureleft"      orientation="horizontal" grid.column="0"/>     <stackpanel name="featurecenter"    orientation="horizontal" grid.column="1"/>     <stackpanel name="featureright"     orientation="horizontal" grid.column="2"/> </grid> </page> 

viewmain.xaml.cs

public sealed partial class viewmain : page {      public viewmodelmain viewmodelmain;      public viewmain()     {                    this.initializecomponent();         viewmodelmain = new viewmodelmain();         viewmodelmain.registerfeatures(this);             } } 

viewmodelmain.cs

public class viewmodelmain: notificationbase {     public modelmain model;     public viewmodelmain()     {         model = new modelmain();         _features = model.loadfeatures();     }      public void registerfeatures(page p)     {         foreach (var feature in _features)         {             feature.addtoview(p);         }     }      observablecollection<iviewfeature> _features = new observablecollection<iviewfeature>();     public observablecollection<iviewfeature> features {         { return _features; }         set { setproperty(ref _features, value); }     }  } 

modelmain.cs

public class modelmain {      public observablecollection<iviewfeature> featurelist;       public observablecollection<iviewfeature> loadfeatures()     {         featurelist = new observablecollection<iviewfeature>();         iviewfeature galleryfeature = new gallery.view.viewgallery();         featurelist.add(galleryfeature);          return featurelist;     }  } 

each feature knows own position on viewmain.xml , implements in viewfeaure.xaml.cs following method register own viewfeature.xaml on viewmain.xaml

public void addtoview( page p)     {         stackpanel target = (stackpanel)p.findname("featureleft");         target.children.add(this);     } 

any professional approach or appreciated.

the problem in line.

target.children.add(this); 

should be

target.children.add(this uielement); 

however, still want know how professional approach feature-based applications might in context of feature-driven development (fdd).


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -