I am using the Slider (https://developer.android.com/reference/com/google/android/material/slider/Slider) in a Xamarin.Android app. However, I need a slider that is vertical, and there does not seem to be a VerticalSlider available. Rotating the Slider makes it very hard to do layout for anything that is not a fixed size (which is almost everything). Are there any good View(s) or relatively simple workarounds available that allow functionality similar to the Slider? I prefer to avoid most third-party downloads for this type of thing, and would prefer that it be a NuGet package if that is my only choice. Any suggestions?
There is no out-of-the-box verticalslider for you.
I think the common method is set property Rotation for the material Slider.
You can put the Slider into a Frame.
Please refer to the following code:
<com.google.android.material.slider.Slider
android:id="#+id/sldPenWidth"
android:layout_width="200dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:rotation="270"
android:value="1"
android:valueFrom="0.1"
android:valueTo="10" />
</FrameLayout>
Related
ItemsControl has an ItemContainerTransitions property that supports <EntranceThemeTransition IsStaggeringEnabled="True" />. I want to move to ItemsRepeater for its improved performance with large lists. But ItemsRepeater doesn't seem to provide any bulit-in functionality similar to EntranceThemeTransition. Anyone know how I might achieve a similar animation effect for ItemsRepeater?
As of right now, there only is a preview API without documentation. You can take a look at the WinUI's MUXControlsTestApp that implemented some examples of using the ElementAnimator to create animations here: https://github.com/microsoft/microsoft-ui-xaml/tree/main/dev/Repeater/TestUI/Samples/AnimationSamples
The simple animation example show in the Windows UWP docs under the section of Visual Layer and sub-section of Time animation is not working...
Above is the code example shown in the docs.
Above is the code of XAML rectangle that I am animating.
Above is the code I have written, similar to the code in first image.
Now this is the error I am getting every time I run the app in debug mode. The property was not found. But that is what is written in docs, then how could it be. One more thing I have tried setting the property to renderTransform as well but that doesn't work either.
What am I doing wrong?
Adding another answer because the one here isn't entirely correct - whilst the example IS wrong, there is in fact a Translation property on Composition Visuals that come from XAML objects - that is also most likely preferable to using offset if your animating a visual of a XAML object.
Firstly, you need to enable the translation property on the element like so:
ElementCompositionPreview.SetIsTranslationEnabled(uiElement, true)
Secondly, you then need to change the animation property to actually target the correct property:
visual.StartAnimation("Translation.X", animation);
This only works if you're targeting the creators update or above.
Using Translation over Offset entirely avoids issues where XAML layout updates break the animation - as XAML position updates will overwrite a Visual's Offset and stop any current animation, whereas Translation animations will continue to run unabated of what the XAML layout engine does.
I believe that the example is wrong. The Visual object have no properties like as "Translation". To move it from left to right,
visual.StartAnimation("Offset.X", animation);
or
visual.StartAnimation(nameof(visual.Offset) + "." + nameof(visual.Offset.X), animation);
I have very simple example code of animate the object with UI.Composition on GitHub. The comments are all Japanese, but it may help you, I hope so.
CompositionGridView
Does WPF have an equivalent to this?
ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(new ColorMatrix { Matrix33 = 0.5f }, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
In other words, can I adjust the transparency of a WPF ImageSource (or any other drawing related class e.g. BitmapImage), or is GDI the best choice here?
I don't intend to draw the image onto a window, so I think that rules out using the Image class(?)
(My line of thought with trying to use WPF instead of GDI is primarily because I'm under the impression that with WPF I can have hardware acceleration, but from what I've seen so far, it seems that it's only applying to a very limited subset of image manipulation)
check out WriteableBitmapEx, which provides a set of extension methods for manipulating bitmaps in memory with WPF and Silverlight.
There is nothing in WPF per-se that will allow you to do want, but the WPF/Silverlight class WriteableBitmap provides a fast, low-level API to drawing/manipulating and is native to WPF.
WriteableBitmapEx then builds on this by providing extension methods to do GDI-like operations. There is a Convolute function which allows convolving an image with a matrix, so you could do the above. Note WB-Ex is a silverlight library but they also provide an unmaintained WPF version which although incomplete, can be extended to keep up to date with the Silverlight version.
Other than that I'd suggest rolling your own. If all you wish to do is modify the opacity to 0.5f then rather than convolve I'd suggest writing a specific function to do that based on the above examples
An image has an opacity field, which is a value between 1.0 (completely opaque) to 0.0 (invisible)
For example:
<Image
Height="107"
Margin="367,0,473,83"
Source="Images/4.png"
Stretch="Fill"
VerticalAlignment="Bottom" Opacity="0.5"/>
Following your comments I created a sample project which can modify the alpha channel quickly using WriteableBitmapEx as a basis and uploaded to my Company Blog. You'll have to forgive the formatting, its a new website and still has some glitches to be ironed out! The download link is on the page titled BitmapAlphaChannel
You're correct in saying WPF's hardware acceleration is only applied to a limited subset of features. For instance, all layout is done on the CPU, tessellation on the CPU, only the final rendering is done on the GPU. The result is WPF in my experience is slower than GDI+, certainly GDI. However it can be pushed in the right direction to do what you want, in the speed you want it to!
I am doing some work for which I need to develop a control, it should be a simple graph that shows several points and two edges.
My problem is that I need to show up to 16k points, with an update rate of 30 Hz. Has anyone done something similar?, and has any advice?.
For example whether to inherit from FrameworkElement or Control (ItemsControl in this case). If the control inherits from FrameworkElememt it may have a better performance drawing the points in the OnRender method but I would miss the Templating feature that comes from inheriting from Control.
Or does there exist another control that can do this out there?
Thanks in advance for your time.
I ended up using InteropBitmap, it is the fatest bitmap rendering class from WPF.
It allows you to map the image that you want to paint (in memory) and then reder it as a Image. This was perfect as i needed to plot points on the screen.
I got great performance (almost 50Hz for 20k points), i also use PLINQ to update the points in memory.
check this article for more details...
Try and read about ZoomableCanvas. I believe it can solve your problem. You can render all the points as small rectangles/ellipses inside the ZoomableCanvas.
I'm working on a c# wpf app in which I want to do something with audio. the irrklang audio library provides me with a pcm decoded 16 bit byte array.
I want to create a timeline control which shows the waveform along the timeline with an overlaying rectangle which the user can drag and click/drag the left and right side to increase or decrease the selection.
It is used to the trim the audio track. I would like the selected min and max to be databindable, the minimum and maximum value of the total track to be bindable.
To clarify here is an image mockup:
I'm not asking for a complete control but tips and suggestions on how to tackle this are more than welcome. Perhaps solutions like this already exist but so far I haven't been able to find it.
I think I need to tackle: the control (zooming, panning and changing the selection) and drawing the waveform in the control
Thanks in advance,
I think you should check out this codeplex project
http://wpfsvl.codeplex.com/
Refer to Audio WaveForm Drawing Using WPF.
Something based upon WaveFileTrimmerControl.xaml would be useful, it uses related controls PolygonWaveFormControl.xaml & RangeSelectionControl.xaml (links are to the XAML but refer to the CS also). In any case it'd be a good starting point for building a control that exactly meets what you want.
You could override the render method and use primitives which will give possibly better performance; but like anything related to performance I'd try the above approach first which is almost certainly good enough.