How a Slider control in WPF can snap on specific values? - wpf

I want to create a slider, with values from 0 to 100 that I can slide like any other slider... but at position 30, 42 and 55 (for example) I want to snap to these values, to make easy to the user to stop the slider at them
edit: my solution was to have 2 slider, the first one is invisible, value 0 to 200, and the other one is the visible on, value 0 to 100
The visible one cannot be slide, only the the invisible. Like this i can make a gap, ex: when I'm between 50 and 75 on the invisible slider, it's equals to 50 on the visible one...

You have to override OnValueChanged. See this article DiscreteSlider - Adding Functionality with a Simple Control Subclass and then this artice Silverlight slider control that snaps for a detailed explanation.
Instead of using SmallChange, you would check where between your values the slider sits and snap to the nearest.

Related

Can we disable/enable tooltip dynamically in Livecharts?

I am using Livecharts in wpf to generate a multiple line chart. The number of lines can be varied from 1 to 30.
For now, I have added a default tooltip which displays all the y-axis values of the current x-axis position where cursor is hovered. So when I have 36 lines in the chart, a larger tooltip is displayed and it does look bad.
So, can I know whether there is any approach which we can enable the tooltip only when the number of lines is lesser that 10 (for an example) and disable when it is above 10?
Thank you!

How to add a progress bar showing the level of a person

I've looked everywhere for a tutorial for this but had no luck.
What I'm trying to do is that lets say if a person has 10/100 XP I want it to show like a image progress bar.
You can make a bar for every one XP. You show them based on what they have. There aren't implemented features for progress bars.
Ill answer my 3 year old question as this post still receives views.
I'd advise using node-canvas as it's the best way to generate a buffered image to send.
Create a canvas (follow the tutorial via the README.md)
Set the width to something of your choice (ex. 500px)
Set the height to something of your choice (ex. 20px)
Calculate the percentage of the XP (ex. 10/100 would be .1 or 10%)
Fill the canvas with a height of the canvas, along with a width of the percentage (in decimal) multiplied by the width of your canvas.
Color the canvas that you filled to your choice (Should be prior to filling)
Enjoy your image generated progress bar!

Slider: How to snap to one tick, but not others

I'm making a media player speed selector, which goes from 0.5 to 2. This is how I have defined the Slider.
<Slider Maximum="2" Minimum="0.5" Ticks="0.5 0.75 1 2"/>
This is because 0.5, 0.75, 1 and 2 is the speeds that is the most desired play-speeds. So I could, if that was the only requirement, say IsSnapToTicksEnabled="True", but the user should also be allowed to select an value between these ticks, and at the same time still be able to snap to the specified ticks.
So, the thumb should snap to these ticks once the slider is close, but not when further away than ~0.1. Is this possible?
We also have the RadControls from Telerik, if there is something specifically implemented there.
What I've tried so far is to listen to ValueChanged and check if the new value is between 1.1 and 0.9, and set it to 1 if it is. But that disables dragging completely.
I did something similar.
I created 2 sliders:
One of them is invisible (from 0 to 100 for example), it's just a rectangle (invisible color) on top on the other slider, this is the one you will slide with your mouse.
The second slider is your graphic, from 0.5 to 2, like you actually have.
Now you just have to code your invisible slider, for example:
If InvisibleSlider < 10, then RealSlider stay at 0.5
If InvisibleSlider is between 10 and 30, then the value of RealSlider is InvisibleSlider * X ?
With that you can simulate that you stick where you have decided, eg: stick at 0.75 if the invisible slider is between 40 and 60, your mouse will move but the the graphic...
I don't know if I'm clear, and english is not my main language sorry

Silverlight Planeprojection

I have a user control that has a white background with a Zindex = 0. I also have an image on top of the white background with a Zindex = 10. When I use planeprojection to flip the image 180 degrees on the X-axis it just shows my image in reverse. How would I get it to show the white background when it gets flipped?
PlaneProjection inherently won't show the "back side" of a container. What you need to do:
Define two elements in your container: one for the front/visible side and one for the back/hidden side
When your PlaneProjection rotation is greater than 90 degrees, hide the front element, and show the back element. Vice-versa for switching back to < 90 degrees
I believe you can use the VisualStateManager to intercept when the rotation angle hits a certain value and to then apply the visibility.
Here is a Tim Heurer article on the VSM:
http://timheuer.com/blog/archive/2008/06/04/silverlight-introduces-visual-state-manager-vsm.aspx

WPF Custom Draw Multiple Progress Bar

In processing a group of items, I wanted to display a unified image of the status of the group, so I essentially made a Grid of a number of progressbars with transparent backgrounds and various colored foregrounds all at the same cell.
I'm running into some transparency artifacts (purple bar is actually purple under the green, and sometimes it draws over the top, etc) and it just seems a bit wasteful. So, I decided to make my own, but now I've got a bit of paralysis on how to do it. Do I use the DrawingContext in FrameworkElement's OnRender, or is there something simpler? Is there a set of general rules when it comes to making your own control?
I pondered switching to a pie chart since those are easy to come by, but its high time I did something not off-the-shelf.
Thanks!
I'm not quite sure how you intend the progressbar to combine different progresses, but if say the furthest along progress is at the bottom of the z-index and the least along progress is at the top, then I'd do something on the lines of this:
1) I would probably create a user control for this new progresbar.
2) It would have a property called NumberOfProgresses, that is tied with an array containing status of said progresses.
3) Each progress would be represented by a Border item (or perhaps something more suitable up the visual tree), because it's a simple wpf control with a background property. The background property would be set to nice a looking progress style and the progress color can be bound in the style to say the border's borderbrush property. Making it easy to set the color of the progress.
4) The user control would have a method UpdateProgress which takes the percentage value and the index of the progress in the array as parameters.
5) As progresses are updated you can either, just calculate the appropriate width (user control actual width * percentage) for the border and play around with the Z index to get it displayed at the top/bottom, or stack the borders horizontaly, set the least along progress as first, then for the rest of the progresses you'd have to substract previous progresses lengths to get the same effect.
This way there would be no transparency induced artifacts and no OnRender()...
Mind you, in WPF there should be no reason to mess with OnRender this and OnRender that, like it was required in WinForms with OnPaint.
Just set up the elements via code to get the look you want, and let WPF do it's rendering ;)
I can imagine one problem with this user control though. You'd have to provide feedback to the user as to which color belongs to which progress. But that would probably take you back to square one, meaning it's better/simpler to just display multiple progressbars.

Resources