Wednesday, April 6, 2016

Prism bits


CompositeCommand
namespace   Infrastructure {
public static class GlobalCommands
{
         static GlobalCommands()
         {
             SaveAll = new CompositeCommand(); // better than field init ??
         }


  public CompositeCommand SaveAllCommand {get; set;}
}

}

//Register child command
Infrastructure.GlobalCommands.SaveAll.RegisterCommand(Save_Local_Command)

// not binding but static ref
<Button Content="Save All" Command="{x:static inf:GlobalCommands.SaveAllCommands}"


Event aggregator---CompositePresentationEvent Publish/Subscribe

View Injection --- using Region Manager or MEF ServiceLocator.GetInstance+Region Manager

Shared Service
using module to host a singleton servivice so that module does not hard-reference another module

infrastructure:IPersonRepository
ServiceModule::PersonRepository : IPersonRepository
Init() { _container.Ressolve<IPersonRepository>(new ContainerControlledLifetimeManager()); //singleton

usage _repository.Save();  //DI IRepository to _repository

RegionContext
DataContext Master/Detail vs Region Master/Detail (Parent/Child)
<ListBox Name="lb" /> <ContentControl prism:RegionManager.RegionContext={Binding SelectedItem ElementName=lb />
DetailView::ctor() { RegionContext.GetObservableContext(this).PropertyChanged +=(s,e)=> { var ctx=(ObservableObject<object>) s; (ViewModel as IPersonDetailViewModel).SelectedPerson=ctx.value as Person;} // note Model Person now in  View, should be inside VM select a person by ID

State based Navigation
Not really move but to update layout, same data/task but different look and feel

Busy Indicator in Async loading 
<toolkit:BusyIndicator IsBuzy={Binding IsBusy}><LisBox/>

Replace Layout by DataTrigger <DataTrigger Binding={Binding IsChecked, ElementName=ToggleBtn1} Value=T>
<Setter Property =ItemTemplate  ItemPanel />

User Interaction through Command -- popup vs in-place editing
DelegateCommand EditCommand
prop SelectedPerson {set {EditCommand.RaiseCanExecuteChanged(); }
<toolkit:ChildWindow WindowState={Binding WindowState}><Grid  DataContext=SelectedPerson >
prop WindowState WindowState

View Based Nav
infrastructure::AppCmds {static CompositeCommand Nav;}
<Button Command={x:static inf:AppCmds.Nav} CommandParam={x:type views:ViewA} . // use type as URI no databinding here.
DelegateCommand<object> Nav_local= new ((obj)=>{RegionManager.RegisterNavigation(ContentRegion,obj);}
Nav.RegisterCommand(Nav_local) // local command has URL set and connect to button by global cmd
Module A/B regtype must use full name of view tyoe as URI
Container.RegisterType(typeof(ViewA)); // very specific syntax here

No comments:

Post a Comment