Get the Height of a ScrollViewer in Windows Phone - windows-phone-8.1

I am having a trouble regarding ScrollViewer in my Windows Phone application (Universal App).
I have a ScrollViewer like the followring:
<ScrollViewer x:Name="myScrollViewer" Grid.Row="1">
<StackPanel>
<TextBlock x:Name="myText"
Margin="12"
FontSize="30"
Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
TextWrapping="Wrap"
/>
<Rectangle Height="140"
Width="400"
Fill="Blue"
Margin="12"
/>
<Rectangle Height="140"
Width="400"
Fill="Red"
Margin="12"
/>
</StackPanel>
</ScrollViewer>
Now I am trying to get the Height of this ScrollViewer. In code behind (inside the Constructor), I have tried:
double d = myScrollViewer.ActualHeight;
double d = myScrollViewer.ScrollableHeight;
double d = myScrollViewer.Height;
I have also tried other height relevant methods to get the Height of the ScrollViewer. But in every case, I got NULL or 0 in the d. Is there any way, that will return the Actual Height or Working Height of the ScrollViewer?

You should be able to get ActualHeight of any framework element after Loaded event of Page. ActualHeight and ActualWidth are not set at the time of constructor or until the control is dynamically calculated/measured etc.

Related

Windows Phone 8.1 scrolling image gallery

I'm creating an image gallery that users can view by swiping an image to the left or right (horizontally) to see the next (or previous) image. Ideally, the image would snap into place like a hub section. I don't want to use a hub, however, due to memory concerns, as well as a hub isn't meant for this purpose.
I'm getting the first image to load, but I cannot swipe or move to another image in the collection. The first image loads, and I cannot slide it left or right.
Any help or suggestions would be appreciated.
Here's my relevant code:
ViewModel
Images = (await _service.GetImages(sectionId))
.Where(i => "Image".Equals(i.Type))
.SelectMany(sr => sr.Images
.Where(ii => "Standard Resolution".Equals(ii.Type))
.ToList();
(This above code successfully returns a list of image objects.)
XAML
<Grid x:Name="ImagesLayout" Grid.Row="1" Height="250">
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Visible"
ItemsSource="{Binding Images}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Url}" Stretch="Fill" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Here's a good article that outlines exactly how to implement an image carousel for Windows Phone 8.1. http://www.captechconsulting.com/blogs/windows-81-image-carousel

Crop image in windows phone 8

I try to crop image in windows phone 8 App.
I use following namespace
xmlns:y="clr-namespace:System.Windows.Media.Imaging;assembly=Microsoft.Phone"
And write content panel like this.
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image HorizontalAlignment="Left" Height="200" Margin="97,153,0,0" VerticalAlignment="Top" Width="200">
<Image.Source>
<y:CroppedBitmap
SourceRect="30 0 75 50">
<y:CroppedBitmap.Source>
<BitmapImage UriSource="/Assets/image.jpg"/>
</y:CroppedBitmap.Source>
</y:CroppedBitmap>
</Image.Source>
</Image>
</Grid>
Error is occurred.
error : The tag 'CroppedBitmap' does not exist in XML namespace 'clr-namespace:System.Windows.Media.Imaging;assembly=Microsoft.Phone'.
If anyone can solve this or do this using another way. please help me.
Use WriteableBitmapExtension library instead which has inbuilt crop functionality.
http://writeablebitmapex.codeplex.com/

How to convert HTML codes to XAML in Windows Phone

I am creating Windows Phone Application, I am getting HTML codes from web service response,
like
" ,<br>"
how do I convert them in xaml?
is there any static method available?
because I have tried HttpUtility mehtod but not getting the converted result
There is no built-in functionality to do this. You'll need to manually map the content to a <RichTextBox /> and insert the necessary <Paragraph /> and <Run /> elements as necessary.
Maybe you could use this HTML to XAML FlowDocument converter: http://blogs.msdn.com/b/wpfsdk/archive/2006/05/25/606317.aspx
Then you could use a custom control, here's an example:
<ControlTemplate TargetType="{x:Type local:ReplyBoxControl}">
<Border BorderBrush="Black" BorderThickness="1" Background="#F0E0D6" MaxHeight="320" Width="300">
<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto" MaxHeight="320" Height="Auto"
Document="{TemplateBinding TestText2, Converter={StaticResource HtmlToFlowDocumentConverter}}" />
</Border>
</ControlTemplate>

how to swap images like only one image display in one page,next image in next page just like windows phone gallery,in windows phone 8

I am new to windows phone 8 development so any one can you please help me in getting the Original size images which is stored into the camera roll (sdcard) in windows phone. and how to swap images like only one image display in one page,next image in next page just like windows phone gallery.I want to develop app that capture images fro camera roll,but all images display same size here i use listbox & scrollviewer(can you provide simple code for this)
You should use Pivot Control and in its content load the image
<phone:Pivot x:Name="PivotAttachment"
ItemsSource="{Binding ObsDownloadedAttachments}" Foreground="Black" FontSize="48">
<phone:Pivot.ItemTemplate>
<DataTemplate>
<Image Grid.Row="1" Source="{Binding DownloadedBitmap}" />
</DataTemplate>
</phone:Pivot.ItemTemplate>
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding ImageUrl}"
Foreground="{Binding Converter={StaticResource ThemeColorBrushConverter}}" />
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<!--Pivot item one-->
<!--Pivot item two-->
</phone:Pivot>

How to remove 'bouncing effect' when scrolling GridView (winrt, xaml)?

I have a page with GridView that contains 5 large rectangles:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<GridView Padding="120,90,46,40">
<GridView.Items>
<Rectangle Width="450" Height="300" Fill="Green" Opacity="0.7" />
<Rectangle Width="450" Height="300" Fill="Blue" Opacity="0.7" />
<Rectangle Width="450" Height="300" Fill="Orange" Opacity="0.7" />
<Rectangle Width="450" Height="300" Fill="Green" Opacity="0.7" />
<Rectangle Width="450" Height="300" Fill="Red" Opacity="0.7" />
</GridView.Items>
</GridView>
</Grid>
When scrolling the GridView to the left and the left rectangle is 'touching' the left side of the tablet screen then all tiles 'bounce' back and forth several times.
Is there any way how to disable this 'bounce' effect? What I have seen is that this 'bouncing' is related to the number of tiles and the width of the screen (in my case it is 1366). When I have more then 6 tiles, the effect is not visible.
The GridView and ScrollViewer have this bouncing effect to show a user he has reached the end of a list. if you don't have this effect it can feel for a user that scrolling is not responding. There is no way to change this.
When you have more then 6 tiles (and you actually have to scroll) this effect will be visible if you scroll to 1 side and then try to continue scrolling.
What do you mean with "back and forth" several times? this shouldn't happen it should only bounce back once. i've copied your code in an empty project and it does not bounce back and forth but only once. (do you have other code that could influence scrolling?)