I have a WPF UI that has 3 i/p controls, 2 dtp and 1 chk box, user will select some value and click search button.
How can I pass values from both dtPicker and chkBox on Button click to a method defined in viewModel?
On click on button, control is coming over to method in view model but how to pass those selected values in method?
You don't need to pass anything, simply set up the bindings correctly.
DatePicker - SelectedDate
CheckBox - IsChecked
Then you'll probably use RelayCommand or something like that and you'll have an easy access to the viewmodel properties.
Related
I want to create a ComboBox having Checkboxes as children using Codename one.
I am not using the UIBuilder
For reusability I created a Container having three Checkboxes in it:
OverviewCheckBoxContainer
- Checkbox1
- Checkbox2
- Checkbox3
and this works already.
As it takes too much space on the screen, I now tried to add the CheckBoxContainer into a Combobox, like this:
ComboBox
- OverviewCheckBoxCont
-...
but it does not work, the ComboBox contains a single entry only and it's not a checkbox, but a text:
OverviewCheckBoxCont[x=...
(cannot see further on the screen)
How can I solve this issue, so there is a dropdown menu containing the three Checkboxes, that toggle onClick?
ps:
In the main form I added the CheckBoxesComboBox instead of the CheckBoxesCont:
this.add(BorderLayout.CENTER, checkBoxesComboBox)
instead of
this.add(BorderLayout.CENTER, checkBoxesCont)
1.You can use simple combobox as shown below
ArrayList al = new ArrayList();
findComboBox().setModel(new DefaultListModel(al));
2.And to add checkbox in combobox , you have to customize the combobox
3.Instead of customizing combobox, You can use button which shows and hides OverviewCheckBoxContainer which contains list of checkboxs
See this for customizing the ComboBox with the generic list cell renderer: https://www.codenameone.com/manual/components.html#_combobox
The problem with using checkboxes in a combo is that you would assume they would all appear in the combo as a set and the combo wasn't designed to do that. I would instead just use a Button and show a dialog with a set of checkboxes then set the text of the Button to match the result. You can style the button to look like a ComboBox if that is your preference.
I have a kendo combobox
#(Html.Kendo().ComboBox()
.Name("ddSystems")
.Filter("contains")
.Placeholder("-- Select --")
.BindTo((IEnumerable<SelectListItem>)ViewBag.systemList)
)
Onchange, a textbox is loaded in ajax. A submit button posts the textbox value and combobox value to the controller. When I get back to the view, I need ddSystems to be reset to empty. I used
$('#ddSystems').data('kendoComboBox').value(null)
and
$('#ddSystems').data('kendoComboBox').text('')
but it always retains the previously selected value. Since I use ajax, this will not display the textbox and I am stuck. Please help.
This will clear the combo box and disable it
Google is your best friend....
var combobox = $("#comboBox").data("kendoComboBox");
combobox.value();
combobox.enable(false);
I have a Region in the top left of the WPF application which I want to be my global button bar where the user chooses which screen they want to view, and the appropriate content will then be displayed in the main region. THere will also be a sub navigation region in the top right with sub-menu options within that screen, eg if the user clicked "Maintenance" from the main menu, the sub menu would show options for New, Update, Delete, Edit etc.
What I want to have is a way to create a custom menu bar by simply specifying a list of Text button names, and ICommand/Parameter pairs for the action to invoke on button click. The natural way to do this would be have a MenuButtonViewModel class with dependency properties Title, Command and CommandParameter. One more would also be needed, IsSelected, so there is some visual way for the user to see which screen you are currently on, so it needs to behave like a toggle button, but where only one button in the group can be selected at a time. I can then have a UserControl where the content of the bar binds to an ObservableCollection and uses data templates to render the button bar.
I have tried a few ways of doing this so far but cannot figure out a way that gives me the visual behaviour I want. These are my requirements
1) Button to change background to a different Brush OnMouseOver
2) When button is selected, a different Brush is displayed as the background until a new button in the group is selected, like a togglebutton IsSelected behaviour
3) Only one button in the group can be selected at a time
The ways I have tried to do this so far are
1) Extending RadioButton with my own class, adding dependency properties for command and commandparameter. Setting all controls to have the same group Id. Data template to override display of radio button to make it look like a visual button with triggers for mouseover and isselected.
This works fine, except for one thing. Once you select a radio button in a group, there is no way to deselect all options in the radio button group. So if you navigate to "maintenance" and then click the sub menu for "Countries" for example, then you are displayed the country maintenance screen. If you then go to a different area of the app and select "Deal Entry" from the main menu, you are taken to the deal entry screen. If you then click "Maintenance", it displays the generic "maintenance" content and brings back the sub menu control for maintenance, where "Country" is selected in the radio button group, but this is undesirable. When you navigate back to Maintenance, it should deselect all sub menu options, display the generic maintenance landing page content and let you select a sub menu option before displaying that screens content. The first time you load Maintenance, nothing is selected, but once you have chosen an option, then there is no way to have nothing selected again when you reload the maintenance screen.
2) I then tried extending a ListBox, styling it with a horizontal stackpanel for the content, each listboxitem is a menubuttonViewModel. This allows me to only select a single option at a time and to clear the selection when you navigate away from the page. It also lets me change the background when you mouse over each listboxitem.
The bit I can't get working with the listbox is to have the background different on the IsSelected trigger. There seems to be some trigger on the default ListBoxItem template that overrides anything you specify in CSS so no matter what trigger I put on the listboxitem or menubuttonviewmodel style, the background simply does not change. I think I need to redefine the data and content template for listboxitem, but only have it apply for this listbox, so it can't be a global template change to all listboxitems - as I want to be able to use listboxes elsewhere in the app without inheriting this behaviour.
Can anyone give their thoughts on these two approaches and how to perhaps solve the issues I'm having to make one of them work in the way I want, particularly if you can advise how I can override the content/data template for the listboxitems in my style so they do not use the default triggers, and I can get the IsSelected trigger working for me?
If I understood correctly, you would want to clear the selection on the RadioButtons from the Sub-Menu each time you navigate back from another Main Menu option.
In order to solve this, you could have every Radio Button "unchecked" by manually setting the RadioButton´s IsChecked property value to false. A possible solution could be the following:
If you want to clear any checked option from the Sub-Menu everytime you navigate to a different section of the Main Menu, you could first notify to the Sub-Menu´s ViewModel by publishing an event using the EventAggregator after selecting and clicking a different MainMenu button, from the SelectionChangedEventHandler method of the Main Menu´s ViewModel.
Therefore, the Sub-Menu EventHandler of the published event would update each RadioButton´s IsChecked property value to false, which it could be accomplished by using a "Two-Way" Binding between each IsChecked property defined on the View, and each boolean "RadioButton1IsChecked" property implemented on the ViewModel.
I hope this helped you.
I am working with Silverlight property grid (http://slg40.codeplex.com/). I would like to put "Button" as property in this grid and implement the "click" functionality of this button.
Main task is: There is workspace(schema) with objects, properties of object are shown in grid, some of objects have their own schema as a property. I want to show this in grid when the button is clicked.
Now only simple types can be shown in grid. If I add complex type it shows result of "ToString()" and small button. By the way this can be a solution but I can't override Click of this button.
Maybe someone had already solved such task?
I have code written on my Listbox mouse double click. I have a submit button too in my form . On mouse double click i want a mouse double click event to be fired first and then the button click
Is it possible?
Please reply
Thanks
Sharath
Easiest (and best practise) is simply to put the code for what to do on Button click into a seperate method (say OnOkClicked), then call this method from the Button Click event handler, as well as at the end of the ListBox DoubleClick event handler.
I nice pattern to implement is to implement an ICommand (like Josh Smith's RelayCommand - google it) on your modelview class, bind the button's Command property to it, and then in the list box's DoubleClick handler, invoke the Executed method of the command. This strucutre simplifies maintaining the logic of:
If nothing is selected in the list box, disable the OK button (Command.CanExecute would return false)
If something is selected in the list box, enable the OK button
If the list box is double clicked, select an item and invoke the OK command.
Hope this helps.
you can make your own control and implement ICommandSource which will give you the same properties