Validating datagrid cell values using Enterprise Library config file - mvvm

In my application,I am working on WPF with MVVM design pattern doing validations through Enterprise Library using configuration file.
I want to validate my grid cell values through enterprise library configuration file.In my view model I have an objservalble collection property that is bound to the datagrid in a view.
Then,I want to validate one of my cell value for range validation using enterprise library..But I am not finding any proper way to do the same.I don't want to use any custom validator rather want to achieve with the enterprise library configuration file only.
Actually while adding a validation to datagrid column we are binding like:-
<xa:ValidatorRule RulesetName="NameOfRuleset" SourceType="{x:Type vm:ViewModelType}" SourcePropertyName="NameOfProperty" ValidationSpecificationSource="Configuration" ValidatesOnTargetUpdated="True" />
But as in this case my view model will not have a property specifically for this field rather it has collection,so i am stucked on how to do the same,
Can anyone please guide me how to achieve the same.Please let me know if my explanation is not clear enough.

Found a solution for the same.
Created a one more class for my collection & in configuration file as well as in view I am refering to that class type only instead of refering to my viewmodel.
Reason why I created new class is I am using Entity framework & i cannot refer to DAL layer in my UI but I can refer to my own type in view.
In this way it solved my problem of adding validation rules to the datagrid that is binded to the collection.
Incase anybody needs sample code,let me know I can provide the same.

Related

Including list view of relationship entity on update page

I am trying to extend an update view to include a list view of some related items below the edit form.
I have two models, Publishers and Volumes, which have a many to many relationship. What I am trying to do is this.... when a user clicks on the edit button for a publisher, I want them to go to a page with the standard edit fields, but also have a list view below the form that lists all of the volumes that are connected to that publisher via their relationship.
Is there an easy way to do this?
I hope this makes sense.
As #tabacitu mentioned, Backpack doesn't currently have an built in solution for this. That said, this could maybe work for you:
This would allow you to use all functionality of the nested list view including interacting with the entities without conflicting at all with the parent
Step 1, Build your normal CRUDs
Build out two normal CRUDs, one for Publishers, and one for Volumes
Step 2, Make a frameless layout
copy vendor/backpack/base/layout.blade.php
name it frameless-layout.blade.php
remove #include('backpack::inc.main_header') and #include('backpack::inc.sidebar')
Step 3, Make a custom list view
copy vendor/backpack/crud/list.blade.php
name it sub-list.blade.php
change the top line to #extends('backpack::frameless-layout')
Step 4, Make a custom field
Create a custom form field that contains an iFrame
Inside your custom field template, have it set the url of the iFrame to the "list" url of the related resource
You'd also need to utilize List Filters and a method for setting them dynamically so that the sub-list shows only the records related to the parent
Step 5, Configure and use the field
In your crud controllers, use the addField to add the the configuration for the new field and its related model
Indeed, there's no standard functionality to do that in Backpack. It's a pretty unusual way to do things. But it's not too difficult to achieve it.
If there aren't too many Vendors for one Publisher (as I expect it's the case here), I would keep it simple and NOT try to include the entire Backpack list view (with ajax, buttons, filters, etc) on top of the form. I would add a standard HTML table with the entries (and optionally buttons to Edit Vendor with target=_blank).
Here's how I would go about it:
In the Publisher CRUD, I would use a custom view for the Edit operation; you can do that using $this->crud->setEditView('edit_publisher_with_vendors') in your setup() method;
In that custom edit view (edit_publisher_with_vendors.blade.php in my example), I would copy-paste everything inside the edit.blade.php view that Backpack/CRUD is using, and add a table with the Vendors on top of the Edit form; notice you have the current entry as $entry in this view; since there's a relationship on the model, you would be able to check if it has vendors using $entry->vendors()->count(), and get the vendors using $entry->vendors.
Hope it helps.

Catel Mvvm Plugins PropertyGrid

I would like to know. How I can dynamically choose view? I would like to make the PropertyGrid in my application. The PropertyGrid should must change when user selects object. As I understand for this task I have to use a DataTemplate but how I can dynamically create DataTemplate in code? The fact is that I use plug-ins and View and ViewModel for each plugin located in separate dll and so I can't directly write DataTemplate in PropertyesViewModel.
How can I make the edit properties for each plugin using the Propertygrid if I can't use a DataTemplate?
For Catel it doesn't matter in which assemblies the views / view models are located since it uses relative naming conventions. However, if you want to show a custom view based on logic that might reside inside a plugin, I think this is out of scope for Catel.
To solve this issue, you must implement a custom service that can communicate with the plugins and resolve the right view for a selected object. One solution might be naming conventions (if it's a PersonModel, you might want to show the PersonPropertiesView and PersonPropertiesViewModel). However, this must be a custom service.

Tableviewer edit and save

I am working on a eclipse rcp application where I am using TableViewer component on a wizard page. I was able to add editing support to the table columns and was able to save the data on the viewer object. Does this edit get saved to actual data? if yes how can I get this updated data within my application to do further processing?
Assuming you are using org.eclipse.jface.viewers.EditingSupport to provide cell editors for the table.
The EditingSupport.setValue method is responsible for setting the new value in the original object provided by the content provider.
To validate values you will either have to write your own CellEditor or use a class derived from one of the existing call editors such as TextCellEditor and overriding appropriate methods.

How to Dynamically load EXTERNAL MVVM and NON MVVM controls using Caliburn Micro

I am loading controls dynamically from the web server from separate XAP files. After creating an instance I want to show them in tab Pages. The controls can be MMVM controls using CM but also non MVVM standard controls.
Before trying the tab I tested to simply show a control dynamically on the page by using:
<ContentControl Name="TestControl" />
Test control is a property of Type UserControl which is set via creating a new Instance of a dynamically loaded control. Now this gives me an error that it can't find the view. In case of non MVVM controls there is of course no view, so how do I load a non MVVM control?
I tried to make the test control a MVVM control, but still get the cannot load view error. Makes sense as such instance is not created. If I create an instance of the dynamically loaded view besides the view model, how do I "Add" this so that CM finds it?
Last but not least, how do I bind this to a tab control in Silverlight? The idea is to have a collection of user controls (plugins) which each is rendered in its separate tab page.
Thanks for any help.
(I got this done in no time NOT using MVVM, still not sure if MVVM is worth all the complexity)
There's no such thing as "mvvm control". MVVM is just a pattern not a control type. Basically, in Caliburn you don't need to work vith UserControls or Views directly, but if you pick the ViewModel first approach, Caliburn framework should be able to find the matching view for you. In your case since you're loading XAP files dynamically, you need to add them to the list of assemblies Caliburn looks to find a View/ViewModel (and bind them together) and this is done through IAssemblySource interface. According to the documentation here:
So, what is AssemblySoure.Instance? This is the place that
Caliburn.Micro looks for Views. You can add assemblies to this at any
time during your application to make them available to the framework,
but there is also a special place to do it in the Bootstrapper.

MVVM User control - where do i declare it to get data from page?

I have a WPF user control ...which is in MVVM. The user control(which contains a listview) need data from the page (where it is included). I have to set a property in View's code behind to get this data input. Will this comply with MVVM(But MVVM pattern do not support adding code in code behind file of view as far as i know).if not, what is the way for the same?
You want to do this via data binding. The controls are bound to properties in your viewmodel which receives the data, applies the needed logic and gives it back to the view for displaying it.
Have a look here to get an idea on how all that works.
I have got a link : http://social.msdn.microsoft.com/Forums/en/wpf/thread/a3eedc3e-0d59-420c-aba0-44fe8b00552f
But I'm not really getting whats meant by injection in it (as given below) :
an interface to the UserControl public model called IUserControlModel. It has the properties that should be visible from outside;
- a UserControlViewModel that contains a public property of type IUserControlModel that is injected in the constructor; plus all the properties used for XAML binds specific to the usercontrol implementation; XAML may have binds directly to the IUserControlModel properties too;
- a MainWindowViewModel that nests the IUserControlModel inside.
I think your problem can be solved in easier way. If you expose ItemsSource property of ListView as Dependency Property of your user control you can achieve what you want without unnecesary (in this case) overhead of implementing MVVM pattern : You then can just use databinding to add data from the page where the user control is included.
post that I think answers your question :
Post link