I am trying to learn to use Expression Blend to build SilverLight UI. I am currently working with the ListBox and have managed to add it to my page. In addition, the list box is data-bound to a sample data source defined in Blend.
But I am unable to figure out how to wire up the selectedItem event in Blend. Is this not possible in Blend and do I need to do this part in Visual Studio?
If you select the ListBox, go to the Properties Pane. Next to the Name of the control there are two buttons - Properties and Events. If you click on the Events button it will switch to showing you all of the Events, of which the SelectionChanged event is listed. Note that there is not a "SelectedItem" event, only the SelectionChanged event. The SelectedItem property represents the currently selected item of the ListBox.
Hope that helps.
Related
I am working with a Visual Basic.NET project in Visual Studio 2017 (.NET Framework 4.6.1)
I am using a Listbox which is associated with a BindingSource.
The Listbox is contained within one pane of a SplitterControl.
I also have a TabControl is located within the other pane of the SplitterControl. This control contains child data associated with the items in the ListBox and is refreshed when the ListBox is clicked and an item is subsequently selected in the ListBox. The Click event refreshes a Treeview, which then populates the TabControl with data if/when (1) a tree node is clicked and (2) appropriate data is retrieved for that node.
The Listbox Click event works fine while clicking different items consecutively within the Listbox only.
However, once the mouse clicks in the TabControl (in the other pane of the SplitterControl), then once the initial Listbox is clicked, the Click event doesn’t fire.
I have researched this issue (on StackOverFlow as well as other forums) and suggestions have basically revolved around the idea that the Click event could be forced by calling the routine set up as the Click event handler (e.g., myListBox_Click).
I have tried this, but the problem is that I am losing the current SelectedIndex / SelectedValue.
To illustrate by reproducing the issue within the app where I am encountering the problem:
The app in question (note the Listbox highlighted by the red arrow - Screenshot 1):
Screenshot 1
Upon startup of the app, the Listbox behaves as it should, if the user clicks nowhere else, only selecting various items within the Listbox. The TabControl (initial tab shown is always the Profile tab) is refreshed accordingly.
However, if at any point, the mouse is clicked in the TabControl (e.g., to select another tab, note Screenshot 2)
Screenshot 2
Now, when the user clicks on another item in the Listbox, the wrong item is selected (shown in Screenshot 3):
Screenshot 3
The Click event is now being forced via a call to MyListBox_Click within the TabControl_Leave event; my thinking was that this was the appropriate place to put the subroutine call. My reasoning was that when the Listbox was clicked in this scenario, the first event to fire (as far as I could tell) was the TabControl_Leave event.
Not surprisingly, if the same item in the Listbox (in this example scenario, Allegheny) is subsequently clicked, than the result is what should have happened on the previous click (that the SelectedValue is correct, as seen in Screenshot 4):
Screenshot 4
Of course, this is correct, since the last click occurred while the Listbox was already the active control.
I have tried several approaches such as (1) using a global variable to store the current index/value and retrieving it, and (2) using the Tag property of the TabControl to store and retrieve the same value. This has either worked inconsistently or not at all because of the order in which the control events fire.
Hopefully, I've been clear enough on the nature of my problem/issue.
Anyone have any ideas on what my next approach could be? Any ideas/insights/suggestions will, of course, be greatly appreciated.
Thanks in advance,
Chris Fleetwood
Software Developer
North Carolina Partnership for Children (SmartStart)
I've taken over a project, which contains some UltraWinGrid controls on some of the forms.
On one of the original forms which has been there since before I took on the project, there is a ContextMenuStrip, which has just one ContextMenuToolstripItem on it, captioned 'Default for Column'.
This ContextMenuStrip is hidden by default, however, when the user right-clicks on the UltraGrid, the ContextMenuStripItem is displayed on the grid (rather than at the top of them form where the ContextMenuStrip is).
I'm trying to replicate this behaviour in a new form that I've added myself, however, after adding the ContextMenuToolstripItem in, I cannot get it to display when right-clicking my grid.
I've put a breakpoint on every subroutine in the in the older forms class, and none of them are triggered when right-clicking it.
Additionally I have also searched the class for DefaultForColumnToolstripMenuItem, and the only place it appears is in the Click event of the ContextMenuToolStripItem itself.
So, how else is it possible to show it when right-clicking the grid? I've copy and pasted the ContextMenuStrip from the old form onto the new form and still nothing occurred.
I'm assuming it's in a property somewhere that I'm missing?
Check for a ContextMenuStrip property on the UltraWinGrid. You can set it in the designer and your context menu will appear on right click without having to deal with the MouseClick handler, checking the mousebutton used, etc.
Is there any XAML control that supports data binding except listview or listbox. I am developing an application using windows azure mobile services table. After retrieving the data from table I am binding the list to a listview as a small preview. When user will select any Item from the list view I want to display the details of the selected item. Which XAML control will be suitable for this task. I can use lots of TextBoxes and assign its Text property from C# code. I dont think It is a good practice. Thank you
If it's a better collection viewer you are looking for for, use a DataGrid. If you want to show more info, it's worth making another panel and showing more data there about the selected item (master detail pattern)
All XAML controls support data bindings. Use DataContext if you want children to access the binding, otherwise you can bind directly on the property.
For example, you could have a separate panel that is a Grid with a few child controls. This Grid's DataContext can be set to the DataGrid's SelectedItem, then it's child controls can easily bind to the item's properties.
I am currently using DevExpress 11.2 within Visual Studio 2010. Currently I am using two DevExpress.XtraBars.BarEditItem which gives me two check boxes (with a label) in my menu bar (DevExpress.XtraBars.Bar) at the top of my windows form. Right now I have working code so that when one checkbox is clicked it unchecks/checks the other checkbox and executes code specific to that box. This works.
My problem is that the DevExpress.XtraBars.BarEditItem does not have a check changed event. Currently I am using the EditValueChanged event as the checked check box is set to True and the unchecked checkbox is set to false. However the EditValueChanged event isn't called until the checkbox looses focus. This doesn't work for me as I want it instantaneous. I looked into the itemClick and ItemPress events but they don't give me the new editvalue and if someone presses on the caption (rather than the box portion) it still fires. Is there someway to get the event right away??
I am looking in two different older projects (both in Visual Studio 2008 and using DevExpress 9.2 and 10.2) and it looks like it does everything the same way as me yet the EditValueChanged event fires right away without any lose of focus.
Actually what you want to do is use the events on the repositoryCheckEdit that is in the BarItem, rather than the barEditItems events directly. It will have CheckChanged and CheckStateChanged Events that you can use.
The repository Item that you want to use for the events will be listed in the Edit property of the BarEditItem.
In Code:
Dim item As New DevExpress.XtraBars.BarEditItem
Dim Editor As New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
item.Edit = Editor
AddHandler Editor.CheckedChanged, AddressOf RepositoryItemCheckEdit1_CheckedChanged
I have two different grid controls on the same form. They share the same context menu. I am having trouble determining which control is the owner when I select the context menu item.
SourceControl property on the ContextMenuStrip class will show the last control that caused that menu strip to be shown.
The event handler for the MenuItem's Click event will have a Sender parameter. This object should be the control that had the focus when the context menu was displayed.