TreeView with custom drawn TreeNode - treeview

I am trying to add a custom icon near the text of a TreeNode, so the items could have a "checked/unchecked" state displayed. I don't want to use a checkbox for that.
Any ideas?
Thanks

Assuming you are using .net and Windows Forms.
You must set DrawMode property of TreeView to TreeViewDrawMode.OwnerDrawAll. Once you do this, treeview's DrawNode event will fire each time a tree node is being drawn. Handle that event and draw your items manually.
You will get DrawTreeNodeEventArgs as the event arguments. State property of it will tell you which state of the tree item you must draw. e.Bounds will help you for determining bounds and you can use e.Graphics for drawing. You can find more detailed information here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode.aspx
But prepare to invest multiple hours.

Related

Assign the same event for multiple components on windows forms designer

My program's GUI has a table with a textbox in each cell. When the user types something on a cell I want my program to get that something, plus the row and column the cell occupies on the table.
Creating an event for each cell manually is a lot of work, and each event would do the same thing, so I was wondering if there's an easier way to do this?
You can use one event handler function for several events, in your case the problem is to determine who has raised the event.
It is important to mention that tablelayout panels don't actually have cells, where you could think of container of objects. Some tricks have mentioned here for how to detect clicked row and column of changed textboxes(this link provided example of buttons but it is the same for texboxes too) but I highly recommend to use GridViews instead.

Implementing a "fisheye" view with a ListBox

I am new to Windows Phone Programming. In my application, I Have a listbox which lists the phone contacts. Currently it is listed as a regular list with equal size for list items in the UI.I am looking to modify the front end like this :
I dont want to have different sizes /back ground color for each list items rather a fixed UI and let the lists scroll through it and the list item in the view, at any time, should be displayed as in the picture.
I dont expect any codes as answers but any examples are welcome too, just want to know using what feature this kind of functionality is possible so that i can do my reading!
Thanks,
Deepak
It would be difficult to modify an existing control (ListBox for example) to act like this, so your best bet would probably be an ItemsControl with its RenderTransform set as a TranslateTransform.
If you place a Rectangle (with Fill="Transparent") over the ItemsControl, you can attach handlers to the ManipulationStarted, ManipulationDelta, and ManipulationCompleted events to control the "scrolling" by setting the TranslateTransform's Y offset.
To resize the items in the list there are two options: a custom panel or manual setting.
Custom Panel
You could create a custom Panel implementation that will appropriately resize its Children based on a property you would create to represent the scroll position. Set the ItemsControl to use your panel, and either through binding or attaching a handler to the panel's Loaded event and keeping a pointer to the panel, update the aforementioned property from inside the ManipulationDelta handler.
Manual Setting
From inside of the ManipulationDelta handler, you can also calculate the various heights of the boxes and use MyItemsControl.ItemContainerGenerator.ContainerFromIndex to get the visual for each item and set its height.
I would suggest putting this all inside of a custom UserControl.
You may have issues with clipping using the TranslateTransform but hopefully this will get you started. Unfortunately, this looks like a rather difficult control to try making as your first windows phone project!
So Finally I did manage to find a way to do it.
First approach was as #Murkaeus suggested, Using UserControl and ManipulationDelta event handler. However for some reason the manipulationDelta event was triggered only for 2 finger gestures (Zoom, Pinch..etc), I have no clue why. And after some trying I had to give up on this.
The next approach was using Listbox itself. The source of the Listbox was set as the List( of Models objects) that I create after reading the contact information from phone. The height and color of the listbox item was bound to a property in my model named "scaleLevel" and was accordingly converted by implementing IValueConvertors to give predefined color and height values for different scale levels.
I created an attached property for the scrollviewer vertical offset like mentioned [here] (http://www.scottlogic.co.uk/blog/colin/2010/07/exposing-and-binding-to-a-silverlight-scrollviewer%E2%80%99s-scrollbars/)!
This event is triggered on change of the vertical offset and every time there is a scroll, I find out which listbox item to be enlarged and which reduced based current vertical offset.
Once I have this information, I change the property ("scaleLevel") of the affected items in the List (of Model) (which is bound to listbox height and color). This change is updated in UI using the INotifyPropertyChanged Event.
I have no idea if this the best way of doing it , but it works well and there is no considerable in updating the UI despite the processing involved.
I would like to hear your opinion about the implementation and any other solution which you feel will work better.

Toggling PanoramaItem Visibility via Delegate

I have a peculiar problem in Windows Phone Development. I have 4 panorama items each of them containing a webBrowser control. On the start of the application, I have only the first panorama item visible while the remaninig are in collapsed state.
Based on the interaction in the first webBrowser, we Notify the WP7 app (webBrowser.ScriptNotify event) and decide which panoramaitems to display. The visiblity is set in the delegate that handles the ScriptNotify event.
the issue I am facing is that though i set the visibility in the delegate to Visible, it doesn't show up in the Panorama. I have tried using Dispatcher in the delegate to change visibility but it hasn't helped:
Deployment.Current.Dispatcher.BeginInvoke(() => {
discussions.Visibility = System.Windows.Visibility.Visible;
});
Can someone suggest what i could be doing incorrectly?
First of all, you shouldn't use a WebBrowser control inside a Panorama. It's very bad performance.
Secondly, Panorama and PivotItems don't have a collapsed state.
And thirdly, the dispatcher have nothing to do with this (unless you're not running the code on the UI thread).
So what you need to do, is to add the PanoramaItems dynamically to the Panorama control. This can be done by databinding (recommended), or directly from C#.
I don't know about performace but i'm sure that a PanoramaItem has a collapsed *visibility* state i tried to toggle it from code and it works like a charm if the initial state is visible.
But if the initial state is collapsed when the panorama loads then it doesn't work anymore. I guess it is because if it is collapsed then it is not included in the panorama and so it won't be visible when you set it to visible.
Maybe that's a bug or i don't know but it is a bit awkward.
To add the PanoramaItem to the Panorama could work.
I'm sorry for not answering the question but the other way around, enforcing the problem :) .
I do have the same problem, one PanoramaItem with an ItemsControl databounded to a collection of the ViewModel. The PanoramaItem visibility property is databounded to {Binding} and a CollectionToVisibility converter is used. During debug with a breakpoint set inside the converter code I managed to see that the return value is ok but the PanoramaItem is not visible when the collections has items.
My investigation took me to realize that in fact when the first get to the Collection occours the return value is null because the Collection data comes from a async call to a service and the converter return value is Visibility.Collapsed, and only when the Collection is populated and the PropertyChanged event is raised, the second get to the Collection property triggers the databind refresh and the return value of the converter is now Visibility.Visible, this leeds me to think that the PanoramaItem isn't included in the Panorama control tree during the applytemplate because the visibility is set to collapsed, and after that the UI never loads the PanoramaItem again.
I made a test to verify this scenario returning in the get of the Collection property an hardcoded list of items so that the first get have items in it and the converter returns Visible in the first get request.Everything works like a charm.I can even string the collection out of items and it gets collapsed and the other way around.
All this is pure Xaml, no code behind.
The intent of this is to hide PanoramaItems that for some reason does not have content to show.
Basically, the panorama keeps an internal list of visible item. This list isn't updated when you set an item to visible. The easiest way to force the control to update this list is setting the MainItem property. So after setting the visibility of your panorama item, just add the following line:
yourPanorama.DefaultItem = yourPanorama.DefaultItem;
(given that the panorama is called yourPanorama)

How does the Outlook app delete checkbox UI xaml code work?

If you tap on the left hand side of the screen in Outlook then an event is triggered (in this case a checkbox appears).
I would like to know the xaml on how this is achieved. It cannot be a simple "MouseLeftButtonUp" event because if you drag your finger more than a few pixels then the event does not trigger.
In my own app I am trying to get an icon appear within a listbox that has a SelectionChanged event. The issue is that if you do not touch the small icon precisely then you are triggering the listbox event rather than the event I want to occur when pressing the image.
I think I need to wrap my image in a Canvas but then am still stuck as to what the event should be.
How do you increase the target size of the area where a user can click on your element?
What event should an image have when within a listbox (which is within a pivot) that has a SelectionChanged event? (MouseLeftButtonUp causes issues if you half drag to the next pivot and lift your finger - it triggers the MouseLeftButtonUp event)
I implemented something very similar to that behavior by making an itemtemplate where the checkbox was pushed offscreen to the left by using a negative margin.
I then created 2 visual states, one for Open and Closed. The open state set the margin to 0, bringing the checkbox back onscreen. Closed state had the negative margin.
With the fluidmove behavior, switching between states on button press was EASY. The only thing you'd have to add would be an invisible button/touch area on the left that would also trigger "opening" the checkbox column (changing state to reset the margins).
Hope that helps...
The outlook app is a native app, so it probably isn't using xaml at all.
If you're worried about the mouse events, then you should look at the gesture stuff in the silverlight toolkit, it contains tap, etc events that make a little more sense on the phone.
Increasing the target size and generally making stuff touchable: wrap it in a Button, then alter the ControlTemplate for the Button to remove the border.
If you look at the ControlTemplate for a Button, (Expression Blend, Edit Template, Edit a copy) you'll see the mechanics of the touch area. It's nothing more than padding/margin.
Thus, you can't bleed your touch region out without altering the layout and affecting other items around the control. I'd do two things:
First, I'd think about whether my whole control should be larger in the first place with good spacing around it. Is my design right?
Second, I'd cheat. I'd float a fixed sized button with no border over the area using the Translate transformation to move it around freely.
Good luck,
Luke

Silverlight 2.0 RC Drag and drop ordering of a ListBox

I am trying to give a ListBox drag and drop ordering functionality and I have hit a wall. I got it to work when I specify the list box items in xaml but it does not work when I bind to a list it no longer works because the items are no longer of a listboxitem type.
I found this code http://blog.dobaginski.com/josh/?p=52 that allows me to get the underlying ListBoxItem but I can't get the mouse move event to fire.
I have went through other tutorials but have not been able to find one that deals with a ListBox. Has anyone done this with a ListBox.
The events I am using are SelectedChange, MouseMove, and LeftMouseButtonUp (I think that name is right). I am not using LeftMouseButtonDown because I couldn't get it to fire.
As far as i know you cannot get at the listbox item container when using data binding. YOu could in Beta 1.
You also cannot set a mouse event handler in the style, you must use a data template, just so you know.
You will likely have to use the mouse move event from a parent element, probably the UserControl or main layout control that hosts the listbox.
State changes and animations need to be in the style though so... you still cant get at the listbox item, just the element inside it in the data template.
Oh and if doing drag and drop HitTest is now protected so that will make the Drop harder.
since today you can download the final 2.0 version of Silverlight with some add ons, check the Scott's web log
I've been trying to do the same thing in WPF,
but have only found many buggy implementations.
One person has guided me towards the blog of Beatriz Costa,
and from what I remember she's one of those rare geniouses,
so I suggest you read that as well... I know I will
Blog of Beatriz Costa

Resources