Using WPF combobox ,datatable, mvvm - binding

I have very simple scenario ,
I have WPF Combo , i am using MVVM , i am assigning a datatable as a datasource to this WPF combo, i am able to assign , able to view data but not sure how to get the selecteditem in my viewmodel layer, i dont want to pollute my UI codebehind .
Thanks in advance for your help

You can create a SelectedDataRow property on your ViewModel and bind the SelectedItem of your Combo to that property on your ViewModel.
This property will be updated when your selected item of the combobox changes and as an extra you can change the selection of your combobox from the ViewModel by changing the SelectedDataRow property.
Make sure that your property raises the PropertyChanged event of your ViewModel

Related

color a cell of a KendoUI grid via MVC controller

In a ASP.Net MVC application I wish to show in a kendo grid column a cell () colored via a color I receive in the form #FFAABB from the controller... how can I do that?
can I just apply the color via style received in the viewbag or is there a better way?
Thanks in advance
First of all, is the color is going to be only one that is being passed from the Controller and if so then you can use Viewbag or a Static variable.
But if the colors are going to differ with each rows of the Grid then its better to pass them along the Model and use a template to set the color, please see a demo I created for the same: Column Coloring from Model

reuse kendo grid but change action

I am trying to reuse a Kendo Grid on MVC by calling it on another view as a partial view. The Read property of the Ajax attribute of the grid is set to some method as follows:
#(Html.Kendo().Grid<MyModel>()
.Ajax()
.Read( read => read.Action("MyMethod", "MyController").Data("getData")))
However, I want that when this grid is called from another view, it changes the 'MyMethod' to 'SomeOtherMethod' and 'MyController' to 'SomeOtherController'. How can I do this?
Thanks!
I have a workaround for what you are trying to achieve. Please see below:
In all the views that you are trying to use the grid, set below TempData value:
#{TempData["ViewPath"] = #Html.ViewVirtualPath()}
Next you need create a generic master read controller action that will call another controller on the basis of the above tempdata value. So in your case in one view it will call 'MyMethod' of 'MyController' and in some other view it will call 'SomeOtherMethod' of 'SomeOtherController'.

How to make Kendo ComboBox or Kendo Dropdownlist to appear as CheckBox?

I have a Kendo UI MVC ComboBox which works fine. However, I want to display the list of items in the ComboBox as a multiselect check boxes. Is there a way to achieve this functionality?
Here is my code snippet.
#(Html.Kendo().ComboBox()
.Name("Country")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((System.Collections.IEnumerable)ViewData["Countries"])
)
I am passing the viewdata from the controller.
Thanks in advance.
Have you considered using the KendoUI MultiSelect control?
http://demos.kendoui.com/web/multiselect/index.html
You might also consider a multi-select grid. I would post a link to the demo, but I lack the reputation. Look for the selection demo within the grid demos.
If you are set on checkboxes, check out this thread. It has a custom template solution using the DropDownList control: http://www.kendoui.com/forums/permalink/5owXK3xeQUKGrE0MgS-Jog

Working with a view without a particular model in mvc

I have a view with one DropDown list and a text box. These two (attributes) are not belonging to a particular model.
Then How can I set the MaxLength property of the Text Box and how can I set the Mandatory validation.?
Thanks in advance.
You can use CSS to set the maxlenght
new { #maxlength="4" }
and use Jquery to do a Valitation
http://jqueryvalidation.org/documentation/

grid binding to a listbox selecteditem runtime

I am a beginner, so please bear with me.
Let's say we have a listbox and a grid that contains textblocks on a window. But these are instanced from separate xaml files, and added to two different stackpanels in the window.
How can I bind the grid datasource to the listbox's selected item in runtime?
I guess what I need to do is to do this following xaml in runtime:
Grid DataContext="{Binding ElementName=lstContacts, Path=SelectedItem}"
Thanks.
You could handle the Window's Loaded event, and in your handler: traverse your Window's children using VisualTreeHelper to find your ListBox based on its name, then set your Grid's DataContext.
Here is a question that discusses, and provides a method for, finding children in such a manner.

Resources