Silverlight zoom area with canvas and scrollview - c#

I have simple canvas with items and i need to add for scroll view as parent for my canvas.
But i fased with problem that after set
canvas.RenderTransform=new ScaleTransform(){...}
Scroolbars not appears or working not correctly.
Will be glad for any information.

The render transform occurs much later in the UI rendering process. It ultimately performs a matrix transform on controls rendering. The scroll viewer will be completely unware of this transform, its scrollbars will be based on the un-transformed size of the original Canvas.
The silverlight toolkit contains a LayoutTransformer control. This control applies a transform to its content as part of the layout process and reports the post-transform size as its desired size.
Consider this:-
<ScrollViewer Width="200" Height="200" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<toolkit:LayoutTransformer>
<toolkit:LayoutTransformer.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</toolkit:LayoutTransformer.LayoutTransform>
<Canvas Width="150" Height="150" Background="Aquamarine">
<Rectangle Fill="Blue" Canvas.Top="10" Canvas.Left="10" Width="30" Height="30" />
</Canvas>
</toolkit:LayoutTransformer>
</ScrollViewer>
Whilst the Canvas has a size (150) smaller than the containing scroll viewer (200), it is scaled so that it would be larger (300). The LayoutTransformer reports its desired size as 300, the post-transform size of the canvas. Hence the ScrollViewer displays scroll bars to accomodate it. Without the benefit of the LayoutTransformer the ScrollViewer would only see the Canvas as having a size 150 despite any applied RenderTransform.

Related

UWP: Do not zoom media transport controls for a media player element inside a scroll viewer

I want to add zoom functionality for media player element(UWP C#) . I placed MediaPlayerElement inside a scroll viewer and zoom functionality is working. But inbuilt media transport transport controls is also getting zoomed and scrolled. I want the media transport controls to be fixed. I tried setting margin and height and width property for transport control. But they do not seem to work. How do I avoid zooming and scrolling of transport control bar
XAML:
<ScrollViewer
Name="ScrollViewerMain"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"
MinZoomFactor="1"
ZoomMode="Enabled"
HorizontalAlignment="Center" Height="314" Margin="427,186,0,0"
VerticalAlignment="Center" Width="730" HorizontalScrollMode="Auto"
VerticalScrollMode="Auto" ManipulationMode="System"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<MediaPlayerElement x:Name="mpe" Stretch="Uniform"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
AreTransportControlsEnabled="True"
MaxWidth="{Binding Path=ViewportWidth, ElementName=ScrollViewerMain}"
MaxHeight="{Binding Path=ViewportHeight, ElementName=ScrollViewerMain}"
/>
</ScrollViewer>
ScrollViewer's zoom is an overall behavior, and its zoom is equivalent to the distance you look at the object.
Objects appear small from a long distance, but the size of the object itself is constant.
When you use ScrollViewer to zoom, it will inevitably change the whole.
So if you plan to manually zoom on the MediaPlayerElement, there are two options:
Get the increment of user operation through PointerWheelChanged or ManipulationDelta event, and change the width / height of MediaPlayerElement by increment.
When the size of the control is changed directly, the icon of MediaTransportControls will keep the original size.
Regarding gestures, this document may be helpful.
Do not display MediaTransportControls of MediaPlayerElement itself, rewrite a transport control yourself, independent of ScrollViewer, and overlay on top, like this:
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"
MinZoomFactor="1"
ZoomMode="Enabled">
<MediaPlayerElement Stretch="Uniform"
AreTransportControlsEnabled="False"
/>
</ScrollViewer>
<MyTransportControls VerticalAlignment="Bottom"
HorizontalAlignment="Stretch"
/>
</Grid>
In this way, when the ScrollViewer is zoomed in, it will only affect the MediaPlayerElement and will not affect the TransportControls.
Update
By communicating with the engineer, we reached a conclusion, The touchpad sends Pointer events rather than Manipulation events. You can handle pinch input from the touchpad with the PointerWheelChanged event.
Best regards.

Scrollviewer to Display a Bigger Image on Windows Phone

I need to display a bigger image at original scale on a Windows Phone 8.1 App.
tried
ScrollViewer
and ViewBox.
None of them seems to work fine.
I want something like when an image is displayed in an html page, scrollable , movable, etc.
Any Idea whether it can be done without embedding a webbrowser ?
<Grid>
<ScrollViewer>
<Image Source="Assets/MyImage.png" Stretch="None" />
</ScrollViewer>
</Grid>
ScrollViewer is designed to handle content that is bigger than the surrounding container.You can scroll image by put image in grid try like this
<ScrollViewer>
<Grid>
<Image Source="Assets/MyImage.png" Stretch="None" />
</Grid>
</ScrollViewer>
In case if Grid is much smaller than the Scroll-viewer then try by giving height and width attribute to scroll viewer

Draw scaled picture over an Image

I have a WPF image, and I'm trying to draw something on it (Lets say a smiley, 2 blue circles for eyes and and a red ellipse for the mouth).
I've made a small Rectangle over the image, and made it stretched.
<Grid Name="mGrid">
<Rectangle Height="0" HorizontalAlignment="Stretch" Stretch="Fill" Name="mImageFrame" VerticalAlignment="Stretch" Width="0" />
</Grid >
I used a DrawingBrush to draw the circles in the rectangle.
Obviously this is wrong, because I have 2 problems:
1. The DrawingBrush seems to have a different scale. It will scale according to the largest item it's drawing.
2. I can only use one brush color.
So, how can I somehow draw over an image so it keeps the same proportions ?
And how can I use a different color for each shape ?
You can put Shapes on a Canvas that overlays the Image, and put the whole thing in a Viewbox. This requires that you define absolute coordinates by either setting the Image's Stretch property to None (and thus force the Image size to that of its Source bitmap) or explicitly set is Width or Height.
<Viewbox>
<Grid>
<Image Source="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"
Stretch="None"/>
<Canvas>
<Ellipse Canvas.Left="420" Canvas.Top="480"
Fill="Red" Width="100" Height="100"/>
... more shapes here ...
</Canvas>
</Grid>
</Viewbox>
One solution would be to put both the drawing and the Image into a ViewBox control. You can find out more about the Viewbox from the Viewbox Class page at MSDN. Basically, it provides the same stretching capabilities as the Image control.
You may also like to view the Shapes and Basic Drawing in WPF Overview page at MSDN.

How do I move an Image in a Canvas without making it bound to the outer Grid it belongs to?

I want to place an Image on the top of a certain tile in a tile based game I am making. Problem is, when I generate the random map, when the Rectangle children of the Canvas is drawn, it draws over the Image. I solved this issue by placing making the Image part of the outer Grid of the Window. Problem is that when I want to place the Image on a certain Rectangle within the Canvas, the co-ordinates are off since the Grid is larger than the Canvas. How can I limit the Image Margins to only that of the Canvas (the canvas borders as the limit) as opposed to the Grid borders as the limits?
E.g. Giving the Image a value of Margin.Left = 50 will place it in the perfect spot in the canvas, but it would be placed on a different location in the grid since its scale is larger.
// Image displays, but does not display when I add child Rectangles to the Canvas
<Canvas Height="700" HorizontalAlignment="Left" Name="canvas1" VerticalAlignment="Top" Width="700">
<Image Name="heroImage" Stretch="Fill" Source="hero.png" Height="74" Canvas.Left="558" Canvas.Top="602" />
</Canvas>
<Grid>
<Canvas Height="700" HorizontalAlignment="Left" Name="canvas1" VerticalAlignment="Top" Width="700">
// Removed the Image
</Canvas>
// Placed the Image outside the Canvas, but now it will draw according to the Grid's Margin limits and not the Canvas Margin limits
<Image Name="heroImage" Stretch="Fill" Source="hero.png" Height="74" Canvas.Left="558" Canvas.Top="602" />
</Grid>
Image inside the Canvas, perfectly positioned
Image in the grid, wrongly placed since I used Canvas Margin co-ordinates
The first way you did it was good, your image should be a child of your Canvas to do Canvas.Left...
To solve you problem can you just put your image on top of all other rectangle, with ZIndex?
Canvas.ZIndex="3 or whatever"
The image with value 2 is drawn over the Rectangle with value 1. So you can pu a high number...
I think that you could use your image inside the Canvas and if you want the image over the Rectangle, the you need set the image's (Palen.ZIndex or Canvas.ZIndex) property greater than the Rectangles one.
For instance:
<Canvas Height="700" HorizontalAlignment="Left" Name="canvas1" VerticalAlignment="Top" Width="700">
<Image Name="heroImage" Stretch="Fill" Source="hero.png" Height="74" Canvas.Left="558" Canvas.Top="602" Canvas.ZIndex="1000" />
<Rectangle x:Name="Some Rectangle" Canvas.ZIndex="1"/>
</Canvas>
The image will be showed over the rectangle. I think this is the solution. Putting the image out the canvas cause will be very complex to set the exactly position you want.

Zooming into image in Windows Store apps

I have a ScrollViewer with an Image Control in it. It displays a rather large image. I want my user to be able to zoom into the image using gestures. I therefore enabled the ZoomMode on the Scrollviewer. However the Scrollviewer automatically scrolls back to the left "edge" of the image whenever the user releases its finger, making effectively zooming in and out of the image impossible.
This is the Template i am using:
<DataTemplate x:Key="SingleItemTemplate">
<ScrollViewer ZoomMode="Enabled">
<Grid Margin="5,0,5,0">
<Image Source="{Binding ImageUrlHighRes}">
</Image>
</Grid>
</ScrollViewer>
</DataTemplate>
How can i solve this problem?
You need to enable the horizontal scrolling as well (turned off by default)
HorizontalScrollBarVisibility = "Auto"

Categories

Resources