I'm struggling to find a way to bind the SelectedItems property in a ListView to the view model.
Previously I used this: http://www.codeproject.com/Articles/412417/Managing-Multiple-selection-in-View-Model-NET-Metr which no longer works in the RTM release.
Any help is much appreciated!
Thanks in advance :)
You could look at the ListViewExtensions.BindableSelection from the WinRT XAML Toolkit on CodePlex.
Turns out binding to the attached property was failing because the type of the attached property was being seen as
From the output window in Visual Studio:
type ('null')
After further research it became apparent that any generic class would fail to bind with this exact error. As a quick fix I simply changed the type to "object".
You can direct bind the selected item to another ui element or a property in your mvvm class
Related
SwifterSwift has a property name cornerRadius.
It's an extension to UIView.
While the DropDown framework has a property name cornerRadius.
DropDown (the class) is a subclass of UIView.
It seems like xCode doesn't know which property I'm referring to.
I only imported one framework to my file but SwifterSwift's extension still takes effect.
I modified the DropDown framework and everything worked fine but then I reverted because it's not allowed and I wouldn't know how to debug any future problems.
I also tried creating a function in an extension to somehow get around this problem.
It turns out that I can't directly access DropDown's table (which is the view that we round).
I cant remove the SwifterSwift framework because it has already been used in the project that I'm working on. Although that might be the best option.
Is there a solution to this problem ?
In Swift, namespaces are implicit and belong to target it is defined. So, for your case, the workaround would be to add the target name in the property call.
SwifterSwift.cornerRadius
DropDown.cornerRadius
Let take example of String. It belongs to Swift target and so I can do this
let str = Swift.String("abc".characters)
Please follow the steps in this issue
Or upvote for adding prefix to all SwifterSwift extensions here
I have adapted the TreeView Control sample project here for use with Entity Framework objects. It works beautifully, but like many others attempting to update collections or properties on their ParentViewModels based SelectedItem changes, I too am unable to bridge the gap of understanding.
I am working in MVVM, and want my code-behind free of any mess. As a beginner, I like the cleanliness of implementing PropertyChanged notifications but since their is no inherent "SelectedItem" property to bind to on the TreeView, I am unable to raise my PropertyChanged event as I normally would with ListBox.
I too have a SelectedItem property (that actually successfully captures the object where isSelected = true) on my ChildViewModel (see H.B.'s answer to this question). I also have a SelectedItem of type ChildViewModel on my ParentViewModel which is bound to my View (see #Martin Liversage's post here). I cannot get them to sync up.
Please help me understand how to communicate the SelectedItem property of my ChildViewModel to my ParentViewModel. I do not bind my TreeView to a CollectionView, so I am unable to get the CurrentItem in the view collection.
My viewmodel collections I'm dealing with are very query-heavy, so I've not included any code for now. Please let me know what is needed for clarity.
So, at least you're starting to get used to your daily MVVM-WTF... 'Why do I have to post on SO for stuff as basic as this'. One day, you'll love MVVM, I promise ;)
That being said: As you know, the TreeView doesn't support synchronizing the SelectedItem property. It does exist, though, but it is readonly. What you want to do, is to extend the behavior of the TreeView to synchronize it's selected item with a property on it's ViewModel.
This problem description points you in the right direction: Behaviors. Behaviors (or, to be precise, System.Windows.Interactivity.Behavior<>s) allow you to extend the functionality of any DependencyObject. (Good introduction)
An approach to synchronize your TreeView with a selected item via behaviors, can be found here:
SO Thread
This should do for you already. You can just copy and paste the code of Steve GreatRex and go for it. Please comment, if you need help with the approach. Have fun learning!
hi I am new to eclipse...
I was trying to do
private Button.OnClickListener btnTestOnClick = new Button.OnClickListener()
and after I type "private Button." there is no content assist...
Is this normal so I have to type OnClickListener or other cases everytime or is there a better way to do this?
The OnClickListener is an inner interface of android.widget.View and shows in the content assist if you start with that class. Inherited inner classes or interfaces are not shown. I believe this is a known bug but can't find a reference yet.
I am trying to find a good way to have a dropdownlist by specifying UiHint "DropDown" to the property of the ViewModel and then just using HtmlHelper EditorFor to render the dropdown via an generic EditorTemplate so that it can be used across solutions. I found a very good approach by Tom Schreck Here It works fine. The only thing from keeping it from being perfect is that the dropdownlist is not part of the validation. If I would like to have a "choose" option (added manually in the EditorTemplate) as default and no value is chosen it results in an error. I believe it's because the DropDownList is not created from the DropDownListFor - Helper? I know that Tom wrote that he tried that one, but is there no way of adding items to the SelectList in the loop with the custom values? I cannot do it since I'm a beginner but I think it would be really great if the dropdown could be inlcuded in the validation. This way you could populate the selectList in the controller and keep the same format as the other properties. Sorry for my vocabulary, as I said, I'm a beginner. But I hope you understand what I mean.
I would really appreciate if someone helped me to solve this as I feel I have tried everything..
Regards max
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