I have a Windows Store app with a Hub page. On one HubSection i show a Image.
The Image should be Zoomable so i add a ScrollViewer and set ZoomMode to Enabled.
But now the Image is not scaled to the height of the Hub anymore. (It uses the size of the Bitmap)
If i remove the ScrollViewer the Image is scaled to the current Height and keeps the Height/Width ratio.
<ScrollViewer ZoomMode="Enabled" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<Image Source="{Binding Image1}" />
</ScrollViewer>
How can i get the ScrollViewer to Fill my Parent? (VerticalAlignment does not work)
Try putting VerticalScrollBarVisibility to Disabled, in that way the image height has to fit the height of the hub control.
Related
I am trying to draw a retangle inside a canvas width rounded corners, when I give this hardcoded the same size as the canvas it shows up perfect.
However when I use these lines to reference parent for width and height:
Height="{Binding ElementName=MyDesigner, Path=ActualHeight}"
Width="{Binding ElementName=MyDesigner, Path=ActualWidth}"
The right and bottom will exceed the canvas, I have attached a picture of the behaviour.
Anyone can give me a hint what is going wrong here?
Edit
The canvas xaml is:
<s:DesignerCanvas Focusable="true" x:Name="MyDesigner"
Background="{StaticResource WindowBackgroundBrush}"
FocusVisualStyle="{x:Null}"
ContextMenu="{StaticResource DesignerCanvasContextMenu}"
Width="300" Height="300">
<Rectangle
Height="{Binding ElementName=MyDesigner, Path=ActualHeight}"
Width="{Binding ElementName=MyDesigner, Path=ActualWidth}"
Fill="Transparent"
Stroke="Black" StrokeThickness="4"
RadiusX="20" RadiusY="20"
Canvas.Left="0"
Canvas.Top="0"/>
<Thumb Name="myThumb" Canvas.Bottom="0" Canvas.Right="0" Background="Blue"
Width="10" Height="10" DragDelta="onDragDelta"
DragStarted="onDragStarted" DragCompleted="onDragCompleted"/>
</s:DesignerCanvas>
The difference is when I change width and height of the retangle to 300 it fits perfectly.
DesignerCanvas, is a class that inherits canvas with few extra functions.
I assume the rectangle is initially drawn (bigger) and then resized to fit the Canvas (which is smaller or became smaller after the whole app was resized to fit the design). But Canvas will never do automatic resize (repaint) of it's children for you which means the changed shape won't show up or redraw itself. It will always show shapes exactly how the look like at the moment when added to the canvas's children.
If you want automatic resize you should choose a Grid or StackPanel as a host instead of the Canvas and set the rectangle's dimensions to Auto or it's Stretch property to 'Fill'. The grids will auto invalidate themselves and then redraw all contents.
Check the remarks of MSDN - Canvas Class. It's explained here...
Alternatively bind the Canvas.Children to a collection of your rectangles. You would then update rectangle dimensions to ActualHeight and ActualWidth whenever the Canvas.SizeChanged event is raised...or manually remove the old rectangle from the Canvas.Children collection and then add the resized one again.
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.
I have a Canvas inside of a Grid in a WPF app. I want to draw a skeleton in Canvas from Kinect data. But the Canvas has a tiny width, probably 1px. The Grid makes it shrink, not keeping its set Width and Height. How to make Grid keep its declared size?
Make sure both the grid and the canvas have HorizontalAlignment="Stretch" and VerticalAlignment="Stretch"
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'
I have an image control in a resizable window with its stretch property set to UniformToFill.
<Image Name="some_image" Stretch="UniformToFill" Margin="0,0,0,0" />
The clipping window is pegged to the top left of the image; resizing chops off the right and bottom of the image.
I want the image to be clipped equally on all sides. Am I being dense and overlooking an obvious solution?
How do I control how the image gets clipped?
(Unrelated: This is my first post to stackoverflow. I just wanted to start off saying, thanks, this site has been amazing resource for me)
The HorizontalAlignment and VerticalAlignment property determine this behavior with an image control.
<Image Name="some_image" Stretch="UniformToFill" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
Guess i was being dense!