Is there a list available for EventTrigger EventNames? - wpf

I do not seem to find a list of available EventNames used in EventTriggers for different UI elements in WPF. I know some of the commonly used Event Names like
Loaded
Click
But it would be nice to get a list of all the event names available for example for a Grid Element.

The best resource for this would probably be Microsoft's documentation. For instance this is a list of all the events for a WPF grid.
http://msdn.microsoft.com/en-us/library/system.windows.controls.grid_events(v=vs.110).aspx

In Visual Studio you can also see the list of available events for a certain control.
They all should be usable as event triggers.
Just click on the respective control in the designer and take a look at the properties tab.
There should be a "flash" symbol at the top right corner of the properties tab. By clicking on it, you can change from "property view" to the "event view" of the control you selected.
You will then see all available events for the selected control.
You can then search for the documentation in the event your are interested in.

Related

Changing the data in a specific area of a window, Caliburn.Micro, WPF

Here is my need. I think a user control is what I need but I am not sure if its the best or even how to use it.
What I have. My main window has a menu with a "help" menu. When you click help, a new window opens, I have a column, At the top of the left column has a drop down box of "Major Titles", a ListBox below that that populates based on the combo box selection. This will be about 25% of the window width. All this works.
When I select an item in the list box a page,contentControl or user control is displayed to the right with verticle scroll bars so the window does not need to resize, the information I display that changes based on the list box selection will have only visuals like text block, label, images. There will be no user interaction with the changeable pages Just formatted Data.
What would be the best way to approach this? Can anyone offer an easy example?
I was thinking of using a user control and change the user control based on the selected list box item.
Ok, I got this figured. After reading a lot of posts and blogs. Seems people sometimes want to make things more complicated then they actually are.
What I wanted, a permanent list box on the left 1/6 of the window. The list box contained string names for "help subjects". On the right 5/6 of the screen I added a groupbox with header and in group box I added a usercontrol. The content of the control is bound to a property called 'ActiveView'. The list box selected value property is bound to 'SelectedListItem' property.
When you change it set 'SelectedListItem' a method is called 'SetActiveControl'. SetActiveControl has a switch/case that sets like in the example:
``Case "Setup":
ActiveView = new SomeSelectionViewModel();
Break;
I have created a user control in a folder inside the Views folder called HelpControls, I also created the same folder in ViewModels. I have classes matching the user controls and everything is bound together.
Ultimately when you click the list box item, the associated ViewModel is called and in turn populates the user control on the window with the appropriate data.
I need to later look into, using one ViewModel for all the controls, I know that can be done using Cal:Model.View = ViewModel name. In the xaml of the control. I'm just not sure how to call the appropriate user control view when an item is selected. Either way this would become a view first design and I thought I read, Caliburn. Micro was intended as a ViewModel first design.

What's the UI design pattern for displaying content in a window when menu item is selected?

I am new to Windows Forms. I have a menu in a form. When a user selects a menu option I want to display some elements like a grid, treeview or a grouped UI elements.
What is the UI design pattern for displaying the view for the selected option? Load a user control dynamically in a pane? Show a form and hide a previous form? I am not using tab control. Content is displayed in a pane in the form. It's not a separate window.
I have searched high and low for sample applications and I couldn't find any which has a menu. Any ideas?
Constructing your form as needed in designer and then hiding and showing sounds like a reasonable approach.
I definitely would avoid dynamic content loading. In WinForms you are most likely relying on events to handle UI interaction. If loading/unloading controls dynamically you would have to take care of hooking/unhooking event handlers. It's easy to keep track of that when you have 3 controls each with single event. But if you have more controls and each controls has to take care of many events the loading/unloading and hooking/unhooking events is going to be error prone. Also unhooked event handlers will result in memory leaks. Other problem is that your complex controls will have many properties. All of them will have to be set up in code. You will end up with dozens of lines listing controls' properties and assigning values to them.
Hiding/showing doesn't expose you to these issues. You design your layout once in the designer. So your main code is not clattered with pure UI construction. Also, you do not create a new instance of a control when you show it so you can subscribe event handlers to events at design time and you do not have to worry about unhooking the handlers when hiding. You create one instance of a control and rely on this instance throughout application lifetime.

Creating a "mergeable" toolbar with Prism regions?

I'm developing a WPF application where I would like a common toolbar along the top of the screen (when I say "toolbar" it won't be a WPF ToolBar control, more likely just a series of image buttons resembling a Windows 8 app bar). I'm using Prism navigation.
What I had in mind was that this toolbar would live in the main window, and always be visible throughout the application. The toolbar would include a couple of standard buttons such as "Exit" and "Help".
Below the toolbar, the main window essentially just contains a large Prism region. When I navigate this region to a view (call it "view1") I want view1 to add additional buttons into the toolbar.
Now, "view1" may have Prism regions of its own, and when one of these is navigated to a view (call it "view2"), view2 should be able to add buttons of its own, alongside the "standard" main window buttons and the buttons added by view1.
It goes without saying that the relevant buttons should be removed when navigating away from a view.
I'm sure I could roll my own solution, but wondered if I could simplify things with Prism? I thought about putting a Prism region in the toolbar alongside the "standard" buttons. "view1" would then navigate this region to a view that basically just contains view1's buttons. This "view1 button view" could itself contain a region, that view2 could navigate to its own "button view". Is this viable, or is it going to get too complicated?
It sounds like you might be complicating it a bit, or at least you lost me at the end...but that doesn't take much today!
A suggestion: Your "toolbar" could be, for example, some ItemsControl where your ItemsSource is a collection of some class ToolBarOperation. This class could contain a description to display to the user and an ICommand to perform when clicked. Style your ItemsControl's items to be buttons and bind each button's command to your class's ICommand. This collection would be populated by the currently visible view's viewmodel (i.e. View1's viewmodel would already know what commands it would be responsible to perform. When View1 is loaded, fill the collection with ViewModel1's list of ToolBarOperation.)
So, to answer your question, I don't think you need anything Prism specific (except maybe their implementation of DelegateCommand)...the "Controller pattern" discussed in the documentation might be helpful. But it shouldn't be hard to accomplish what you want with Prism alongside.

C# - How does the ToolTip work?

I was wondering how I am able to add one ToolTip control to the Form, and all the buttons get different texts? How does one object extends all the others, adding diferent things on each one? I don't know if I am being clear, If I don't, please let me know!
Thanks in advance!
I think you are looking for Extender Providers, where you can define new properties for other components.
This is a feature of Visual Studio designer. The ToolTip control does not actually add a property to other controls, but Visual Studio knows that when you have a ToolTip (or any other component that is an Extender Provider), it should add some other properties to property grid of the other controls. All this information is queried from the component that provides those properties (ToolTip). When you set the tooltip for button for example, Visual Studio calls the SetToolTip method of the ToolTip control, to inform it of the new value for the control.
Please refer to provided links for more information.
It's actually very simple.
Lets say you have a windows form with two controls a button and a label.
Now add a tool tip from toolbox to your form named tooltip1.
Now right click on button and go to properties, scroll down until you find tooltip on tooltip1. set the text to whatever you want. Now do the same for label.
Run the program and move the cursor over both the controls. you'll see respective tool tips.

How do I add a MouseDoubleClick event handler on a ListBox using the Visual Studio Design view?

I wanted to add a DoubleClick handler to an item in a ListBox (assume it is called ListBox), but I could not get it to appear using the Designer view.
I.E., double-clicking on the ListBox, I would only ever get ListBox_SelectedIndexChanged handlers wired up for me. (My list-box items are programmatically assigned, so there were no items in the Design view to click on -- is that an issue?)
I did work around this by coding up the handler myself (based on C# Listbox Item Double Click Event) but that took further research, since I had no idea that instead of looking for a MouseEventHandler in System, I had to drill down to System.Windows.Forms.. How annoying.
I.E., this.ListBox.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.ListBox_MouseDoubleClick);
So, is it possible to auto-generate a MouseDoubleClick event in the Design view?
Or do they have to be wired up by hand?
Not that I'm lazy, or anything. Other than using Visual Studio, I mean......
You can use the Events view in the Properties tool window to generate a handler for almost every event (some generic event handlers are not supported, as I remember). To auto-generate an event handler, double-click the empty field next to the event name.
For your case with ListBox.MouseDoubleClick, here's how to do it:

Resources