I have a form that has the following objects listed:
public string Title {get;set;}
public string Description {get;set;}
public List<Items> Items {get;set;}
I am trying to create a form that allows for the items to be shown as checkboxes, with the ability to select as many as you want before submitting. The issue is I can't seem to find a clean way of doing this. I have tried using CheckboxFor but I am not sure this is the correct use case.
Related
I am making an MVVM WPF program and want to bind a childgrid to a single item in a parent collection, I am using telerik (RadGridView).
The situation is as follows:
public class ItemDetails
{
Item item {get; set;}
string version {get; set;}
}
public class Item
{
ObservableCollection<ItemVersion> itemVersions { get; set;}
}
public class ItemVersion
{
string version {get; set;}
ObservableCollection<ItemVersionSubItemVersion> subItemVersions {get; set;}
}
public class ItemVersionSubItemVersion
{
ItemVersion parentItemVersion {get; set;}
ItemVersion subItemVersion {get; set;}
}
I bind an ObservableCollection< ItemDetails> to my RadGridView and depending on what Version is requested in ItemDetails, I want to show all SubItemVersion members of the ItemVersion with that correct Version (Version will allways be unique and if there is none available a new ItemVersion will be created with an empty ObservableCollection< SubItems>).
The only way I got this semi-working was by first showing all ItemVersions in Item and then going to the SubItems, but this shows irrelevant ItemVersions aswell and not just the one I need. So I want to skip a link in the chain, so to speak, and go straight to the SubItemVersions.
I was wondering if anyone knew how to either be able to select a certain item from a collection in xaml, somewhat like a linq query, but in xaml, or some other way to directly go to the SubItemVersions of the right ItemVersion.
A few requirements and ideas I had that made it difficult for me to come up with a solution myself:
The whole thing needs to stay in one view, so the user can keep a good overview of the structure (a SubItemVersion can have SubItemVersions of its own, which can get messy rather quickly).
It needs to be MVVM, so it would be best if the code behind of the view is avoided, pure xaml is strongly preferred.
I would prefer if the models do not need to be changed, but, if no other solution is available, I will have no other choice but to do so.
I thought of changing the following:
public class ItemDetails
{
Item item {get; set;}
string version {get; set;}
}
to:
public class ItemDetails
{
Item item {get; set;}
ItemVersion version {get; set;}
}
But this would add an ItemVersion that is already in the ItemVersions collection in Item, so I am generating more (duplicate) data than necessary, correct? Or is this, in fact, a proper solution?
Any idea or input is welcome and greatly appreciated and if you need more information, please let me know so I can try and provide it.
EDIT:
I solved my problem by creating a new ViewModel which contains
ItemVersion version
ItemDetails details
And created a collection of this new class to bind to the details, where version returns the right version, taken from details. This seemed like the best solution and quite simple to achieve.
I solved my problem by creating a new ViewModel which contains
ItemVersion version
ItemDetails details
And created a collection of this new class to bind to the details and version, where version returns the right version taken from details. This seemed like the best solution and quite simple to achieve.
Using ReactiveUI 6.5, I'm trying achieve something like a SelectMany LINQ expression with the CreateDerivedCollection feature of RxUI. The objects in my source collection (type 'A') have an IsSelected property, as well as another collection property where the items are of type 'B'. I want to end up with an IReactiveDerivedList<B> which is a flattened list of all of the B objects from the A's that are selected. Hopefully that makes sense.
To make it a little more concrete, let's use an example of an app for browsing log files. Say we have a LogFileViewModel type and our main screen's view model has a list of these. Each instance in the list represents a log file on the system, and we present a list of these that the user can select. It's a multi-select list so they can select more than one at a time.
The LogFileViewModel then has an IsSelected boolean property, which will be set to true/false as the user selects or deselects the corresponding item in the list. And it has a property which is a List<LogEntry>. Each LogEntry object of course represents one entry in the corresponding log file.
What I want to do then is have a reactive list in the main view model which is a list of all of the LogEntry objects for all of the currently selected LogFileViewModel objects. The ReactiveList of selected log files is easy, but I'm stuck on the second part. Here's what the main view model would basically look like:
public class MainViewModel
{
public MainViewModel()
{
//This gets initialized with the log files somehow, doesn't matter
LogFiles = new List<LogFileViewModel(...);
SelectedLogFiles = LogFiles.CreateDerivedCollection(l => l, l => l.IsSelected);
SelectedLogFileEntries = ? //How to create this one?
}
public List<LogFileViewModel> LogFiles { get; private set; }
public IReactiveDerivedList<LogFileViewModel> SelectedLogFiles { get; private set; }
public IReactiveDerivedList<LogEntry> SelectedLogFileEntries { get; private set; }
}
Is there a known way to do this that I'm just not seeing? If not, any clever ideas to achieve this behavior? :-)
Edit :
Looks like I missed this question in my initial search. Paul provided the "clever" solution to this problem about 2 years ago. So my question now ... is this still the best way to achieve this behavior?
I am creating a dashboard, on this dashboard I have multiple instantiations of the same web user control.
Each web user control contains its own hidden fields. These hidden fields overwrite each other which causes it to always return the last set value for all the instantiated web user controls.
Is there anyway I can get around this?
[Edit:]
This is what is supposed to happen:
I advice you to use that kind of data modeling in order to use one hidden field for each usercontrol:
public class MainModel
{
public List<UserControl> {get;set;}
public string otherfield {get;set;}
}
public class UserControl
{
public string showableField {get;set;}
public int hiddenfield {get;set;}
}
See more for model binding in scott hanselman wensite
I am about to upgrade our software from ASP.NET WebForms to .NET MVC. All over the web it shows how to create a view based on a model, which is fine.
In this project the users can hide properties of the model to generate a view suitable for them, yet another client in another website and hide other properties.
The code is all the same, but i would like to know if there is a way to hide/show properties of a model based on a condition easily, hopefully without having a lot of IF statements all over my views.
Example - How can 1 client see only name and town, yet another client see all 3 properties. Just need to show based on a condition.
public class MyObject() {
public property name { get; set; };
public property town { get; set; };
public property customText { get; set; }
public MyObject() {}
}
NOTE: Users can also determine the order of these properties, can i do that as well easily ?
Just to say that creating separate views is not possible. The above is a very simple example of a model with properties. Our models can have about 100 properties, and the user can turn these on and off whenever they like, so it needs to be able to be done dynamically
Is there a way of creating a ViewModel on the fly?
Thanks in advance
Create a Property class or similar and model you data appropriately:
public class Property
{
public string Name {get;set;}
public bool Visible {get;set;}
public int Order {get;set;}
}
Then your view model can be similar to your example:
public class ViewModel
{
public Property Name {get;set;}
public Property Town {get;set;}
public Property CustomText {get;set;}
}
Well you cannot bind multiple models to your view.Obviously you have to do workaround in your view based on user roles.
Or else create a seperate model and view for each user roles.
I have been working on a project called Dynamic MVC.
http://dynamicmvc.com
It currently does not do what your asking. The functionality is already there, it is just not exposed the way you need it. However, if you are interested I will add the functionality so you can pass the properties you want to display in the querystring. Eventually, a customizable dynamic view will generate your page for you without any coding required. Also, the order of the properties would determine the order on your page. This would work for any model with the DynamicEntity attribute.
Let me know if your interested and I can include it in the next release.
I am attempting to find a way to alter the information that is shown in a DataTip in the VS 2010 Debugger. The purpose being that I would like to choose what property value is shown on the initial window of a DataTip.
For example, when hovering over a collection in debug mode I am presented with the Name of the collection followed by its Count property's value.
This is useful information, but when I am hovering over one of my custom objects I am only presented with a path providing the type of object it is (in my case something like BOS.SuggestedOrdersDataEntity.SuggestedOrdersEntity).
I would like to have this initial DataTip window contain the property that I would determine to be the most useful depending on what custom object it is. For instance it could be the case that for an object that is of type SuggestedOrdersEntity it would be more helpful for the DataTip to show the value of its VendorName property in place of BOS.SuggestedOrdersDataEntity.SuggestedOrdersEntity (similar to the way collections show their Count property). The goal is to not have to use the '+' expander to find the current value of the VendorName (or whatever property is most useful).
I would like to be able to alter the DataTips so that I can customize them to immediately show a specific property's value (just like Count shows for collections) without needing to expand and view all the properties.
Does anyone know if this is possible? I've done some researching on DataTips, but nothing I have found discusses customizing them in this way...
You can use the DebuggerDisplay attribute, examples here.
[DebuggerDisplay("{Name} - {StockSymbol}")]
public class Company
{
public string Name { get; set; }
public string StockSymbol { get; set; }
public IEnumerable<Employee> Employees { get; set; }
public Company(string name) { Name = name; }
}