Saturday 15 January 2011

c# - Self-Deleting Viewmodel in detail view - Bad Practise? -


I have a master-extension application that has the ability to order removal in the expanded view / format.

How can I inform the master-collection in the master-view model that the expansion-vododal has been removed and it has been removed from the collection?

Is it a bad design and master-view modell to remove the extension? Or is the only option to do this through an event? MVVM analog

Here's a little code

ViewModel

  public class AllMetalTransactionViewModel: WorkspaceViewModel {private ObservableCollection & LT; MetalTransactionViewModel & gt; _metalTransactions; Public supervision qualification & lt; MetLtransaction Videodel & gt; Metal implants ({return _ Metal Transaction;} set {if (set ( "metal transactions", ref _ metal transaction value)) {}}} private Metltronssevijivmodl selected metal Tronssekshn; receive public Metltrensakshnuvymodl Cynitmetltronssns {selected {elected the metal transaction;} set {if (set ( "SelectedMetalTransaction", Ref _selectedMetalTransaction, value)) {}}}} public class MetalTransactionViewModel: WorkspaceViewModel {private RelayCommand _deleteCommand; public relay comma In Command Nd Delete Delete Command {return _ ?? (_deleteCommand = new RelayCommand (() = & gt; {(IsNewUnit) {_dataService.DeleteMetalTransaction (_metalTransaction, CallbackDelete) if ;! _dataService.CommitAllChanges (representatives (bool b, object o ) {}); // How can I notify AllMetalTransactionViewModel I have been deleted? Events?}}, () =>; IsNewUnit)}}}   

XAML Master

  & lt; View: MetalTransactionView Grid.Column = "1" DataContext = "{Binding selected MetLtrontation}" & gt; & Lt; / See: MetLransactionViews & gt;   

XAML-details

  & lt; Button DockPanel.Dock = "right" HorizontalAlignment = "right" padding = "5" content = "Laisshain" Margin = "5" width = "80" Command = "{Binding Path = Htanakom}" / & gt;    

Good day to you!

You can do so many ways (I like A and D solutions):

A. Extension view model has a link to master extension view model (a method some light interface with zero, RemoveDetail (MetalTransactionViewModel details) ) or see a collection of details for example model For there links):

View details Model:

  Public category MetalTransactionViewModel: WorkspaceViewModel {Private RelayCommand _deleteCommand; IList & LT; MetalTransactionViewModel & gt; Receive pants } Public Relay Command Demand Command {get {delete_deleteCommand ??} (_deleteCommand = New RelayCommand (() => {if (IsNewUnit) {_dataService.DeleteMetalTransaction (_metalTransaction, CallbackDelete); _dataService.CommitAllChanges (Rep (bool b, object o) {});; (ParentCollection == Faucet ) {Return;} If (PainterCollection.Composition (this)) {PaintClockclause.Exclude (this);}}}, () => ISNEINET);) }}}   

From the main view model, creating expansion model:

  private MetalTransactionViewModel CreateDetailViewModel () {new MetalTransactionViewModel return () {ParentCollection = MetalTransactions}; }   

b. As you use an event you say (but be careful , because it can bring a memory for you leakage ). Please, review

c. If you are using the MVVM Toolkit, you can use the master visual model class of Remove Action to notify you of such a.

D. Remove the command in the main visual model I think this is the best solution in this case. I believe the Main Visual Model Collection Collection Details View Model .

I hope this will help you!

No comments:

Post a Comment