Inside ScrollViewer control I have a large image and I want to use scroll bars to move that image inside ScrollViewer. See XAML code below:
<ScrollViewer HorizontalAlignment="Left" Height="282" Width="554"
HorizontalScrollBarVisibility="Visible" VerticalScrollMode="Enabled">
<Image HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top"
Source="Assets/big_image.jpg" Stretch="None" ManipulationMode="None"/>
</ScrollViewer>
This works fine on my PC. I can use mouse to move image inside ScrollViewer by using scrollbars. But when I deploy application on the tablet, I cannot do anything. The scrollbars are not visible and I cannot use gestures to manipulate the image. Does anyone know how can I solve this problem?
There is a Microsoft example with similar functionality:
http://code.msdn.microsoft.com/windowsapps/XAML-ScrollViewer-pan-and-949d29e9
This example uses a Scrollviewer with an inside image to show the capabilities of the ScrollViewer control to pan and zoom. I tried it with a tablet and it works well.
Hope it helps.
Related
I am trying to make responsive WPF app which shows image. One of the program's functionalities is selecting a piece of an image by clicking and draging the mouse. I use Point p = e.GetPosition((IInputElement)sender); to find cursor position, and I found out I cannot use Stretch="Fill" because it causes the MouseUp cursor to select a little lower than it should and MouseMove is also inaccurate (I have to drag the mouse a lot further than I should). On the internet, I found the reason for this behavior that you cannot use Fill and have to use None instead. However, the image is much smaller without Fill.
This is my XAML:
<Grid Grid.Row = "1"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment= "Top"
Margin="0,30,0,0">
<Image x:Name= "image1"
Grid.Row = "1"
Grid.Column="1"
Cursor="Cross"
MinWidth="300"
MinHeight="300"
MaxWidth="512"
MaxHeight= "512"
Stretch = "None"
RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased"
VerticalAlignment="Top"
MouseDown="picOriginal_MouseDown"
MouseMove="picOriginal_MouseMove"
MouseUp="picOriginal_MouseUp" />
</Grid>
I don't know how to embed my image so that in the window view it fills the grid without this Fill property and at the same time is responsive for fullscreen. Should I wrap Image with something else from the WPF toolbox?
I find it easier using the background of the picture box to be the image then use the stretch in that. Alternatively, you could use the image with any of the other options, try using the the properties tab, here are the other stretch options tho: None, Fill, Uniform, UniformToFill
Tell me if this helps, tryna get rep, thanks!
I'm writing a WPF desktop application, with some video playback functions. I decided to use LibVLCSharp.WPF to complete the playback task.
Xaml code:
<UserControl ...
xmlns:vlc="clr-namespace:LibVLCSharp.WPF;assembly=LibVLCSharp.WPF"
... >
<vlc:VideoView VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Canvas VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MouseEnter="Canvas_MouseEnter">
</Canvas>
</vlc:VideoView>
</UserControl>
It works fine with playing video, but when I tried to put some hidden controls inside Canvas (or any other type of Panel control) and change their visiblity with MouseEnter event, nothing happens.
While debugging, I found out that MouseEnter event can only fire when Canvas has at least one visible control as its child, and mouse pointer entered that visible control.
I have read the articles about "airspace issue". It seems nothing to do with me since I just want to draw a control layer exactly inside playback area.
Is there any way that I can put an auto show panel on VLC player, which only shows when mouse "hovered" over playback area?
Problem solved with hint from #cube45 . Thank you.
I changed Background of Canvas to something that "not so transparent".
Xaml code:
<Canvas Background="#01000000" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MouseEnter="Canvas_MouseEnter">
</Canvas>
And mouse events worked. Tricky, but useful.
I'm working on updating previously working app. Testing shows the ScrollViewer acting oddly when the Zoom makes part of the contained images fall off the screen. The original app was created with VS 2013 as a Universal Windows app. The new app is created with VS 2015 as a Universal Windows app though the target build has been shifted to the anniversary release.
My XAML is defined so:
<ScrollViewer x:Name="SV1" Grid.Row="1" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
SizeChanged="SV1_SizeChanged" ZoomMode="Enabled" >
<StackPanel x:Name="ImagePanel" Orientation="Horizontal" HorizontalAlignment="Center"
VerticalAlignment="Top" >
<Image x:Name="ImageLeft" Stretch="Uniform" />
<Image x:Name="ImageRight" Stretch="Uniform" />
</StackPanel>
</ScrollViewer>
The user can change the ZoomLevel of the ScrollViewer. The zoom change is implemented using SV1.ChangeView(null, null, zoomFactor).
The images visibly change size on the screen, but as they fall off the right or bottom the scrollbars don't appear. Even changing the visibility properties to "Visible" instead of "Auto" doesn't cause the scrollbars to appear. When the size changes and for a brief instant a thin line will appear where the bars should be and then disappear. Additionally, user input that would normally scroll like moving the mouse wheel does nothing.
Based on other commentary, I've tried replacing the StackPanel with a Grid with no apparent effect.
I'm drawing a blank. Any ideas?
It appears the answer is the next control which shares the same visual space needs to be set to Visibility="Collapsed" in the XAML. The visibility is controlled programmatically, but without the XAML tag the scrollbars of the previous control don't appear and with the tag they do.
I'm creating a simple slideshow on UWP using C#/XAML
I've got a problem with the zoom on image.
In fact when I zoom, if I try to move the picture, it moves, but when I remove my hand, the picture is coming back to a "default position" like it was linked to a border or something like this...
Here is sample of my XAML
<FlipView x:Name="flipView" Grid.RowSpan="2" VerticalAlignment="Top"
Margin="0,280,0,0" Height="1490" Background="Black">
<FlipViewItem Height="1620" Width="1080">
<ScrollViewer ZoomMode="Enabled">
<Image x:Name="image" Source="Images/test.jpg" VerticalAlignment="Top"
Height="1610" Margin="0,10,0,0"/>
</ScrollViewer>
</FlipViewItem>
Do you have any idea of what can cause this ??
I just solved the problem by adding horizontal and vertical scroll bar option on auto
It's because the MaxWidth and MaxHeight of your page is becoming smaller than the image itself.
Have a look at this blogpost which gives a good solution:
http://igrali.com/2015/07/16/why-is-my-zoomable-scrollviewer-snapping-the-image-to-the-left/
I have a Windows Store app with a ScrollViewer and an Image in it. When i double tap on the ScrollViewer I want it to zoom the Image to its width. This part is not a problem but I also want the Image to be centered after it has beed zoomed in.
I tried calling the ScrollToHorizontalOffset method on the ScrollViewer but It does not seem to work with any number I give it. What is the problem?
Perhaps the offset only works for the non-zoomed view where your image fills the ScrollViewer completely and thus can't be scrolled. You could try setting the image dimensions so that it is larger than the ScrollViewer, but set original ZoomFactor, so that it fills the ScrollViewer at first. Then zooming and scrolling might work.
Assign a SizeChangedEvent in the scrollviewer.
<ScrollViewer SizeChanged="OnSizeChange"></ScrollViewer>
like this. Then it is better to place your image inside a canvas. So your code will be probably like this.
<ScrollViewer SizeChanged="OnSizeChange" x:Name="scrl">
<Canvas RenderTransformOrigin="0.5,0.5" x:Name="main">
<Image source="" Canvas.Top="insert desire double value here", Canvas.Left="Same goes here"/>
</Canvas>
</ScrollViewer>
then in the code behind you can change the height and width of your canvass depending on the scroll viewer
Main.Width = scrl.ViewPortWidth;
Main.Height = scrl.ViewPortHeight;
You can experiment on the size of the canvass while adding a double tap event to it. Changing the size of the canvas can zoom in or out the image because the image is inside the canvass
Try with 'ChangeView' instead of 'ZoomToFactor'