I have a simple page that is supposed to display an image. On my android app it fits to the phone screen, but on my UWP app running on a laptop the image expands out of the window. I have tried all different aspect options and different Horizontal and Vertical Orientation options with no luck.
My page looks like this:
<ContentPage.Content>
<StackLayout >
<StackLayout VerticalOptions="Center" >
<Image Aspect="AspectFit" Source="{Binding ImageSource, Converter={StaticResource LocalByteToImageFieldConverter}}" />
</StackLayout>
</StackLayout>
</ContentPage.Content>
And the output looks like this:
Android:
UWP:
I'm guessing its something small I'm missing but cannot find the right style settings.
try this , may be helpful for you
<Grid VerticalOptions="Fill" HorizontalOption="Fill" >
<Image Aspect="AspectFit" Source="{Binding ImageSource,
Converter={StaticResource LocalByteToImageFieldConverter}}" />
</Grid>
try use Image Source="aa.jpg" Aspect="AspectFill"
Related
In the following XAML, I have a Frame that contains an AbsoluteLayout that contains an Image and a Label. I want the Image to be left justified and the Label to be centered (in the entire AbsoluteLayout object). Here is my XAML:
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<AbsoluteLayout BackgroundColor="Black">
<Image Source="{local:ImageResource App.Raindrops.png}"
WidthRequest="40"
HeightRequest="60" />
<Label Text="Sprinkle"
HorizontalOptions="Center"
VerticalOptions="Center"
TextColor="White"
FontSize="36"/>
</AbsoluteLayout>
</Frame>
No matter what HorizontalOptions and VerticalOptions I use, I always get the following...
Notice that the label is not centered. Am I using the wrong layout? Am I missing, or using some wrong, attributes?
I am building the application in Visual Studio as a Xamarin.Forms app, and the deployment is being done to the standard Visual Studio Android emulator.
I found one solution here (which also has a great discussion on overlaying in XAML). The modified XAML is:
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<AbsoluteLayout BackgroundColor="Black">
<Image
Source="{local:ImageResource App.Raindrops.png}"
WidthRequest="50"
HeightRequest="60"/>
<Label
Text="Sprinkle"
TextColor="White"
FontSize="36"
AbsoluteLayout.LayoutBounds="0.5, 0.5, -1, -1"
AbsoluteLayout.LayoutFlags="PositionProportional"/>
</AbsoluteLayout>
</Frame>
... and the result is this ...
... which is exactly what I wanted.
By the way, I came across this little tidbit in the documentation page for AbsoluteLayout:
I work on a Xamarin.Forms app that will contain a page with 2 CollectionView items:
an horizontal CollectionView that will display events
a vertical CollectionView that will display posts
I would like that the first list is progressively hidden as soon as the user starts to scroll on the second list.
We can found this behaviour on a sample from Syncfusion: but they use a SfRotator as control for the horizontal list:
I've tried to reproduce the same behaviour on my page, but it doesn't work as expected. My horizontal list is not hidden until I scroll vertically on this first list itself. If I scroll on the second vertical list, the first list is still visible:
My XAML looks like this:
<ContentPage.Content>
<RefreshView x:DataType="vm:NewsViewModel"
IsRefreshing="{Binding IsRefreshing}"
Command="{Binding RefreshCommand}">
<ScrollView>
<StackLayout Padding="16" Spacing="16">
<CollectionView x:Name="EventsListView"
ItemsSource="{Binding Events}"
HeightRequest="250"
VerticalScrollBarVisibility="Never"
SelectionMode="None">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal"
ItemSpacing="20" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<ctrl:ShadowFrame BackgroundColor="Red">
<StackLayout x:DataType="model:Event" >
<Label Text="{Binding Name}" />
<Image Source="{Binding Image}" />
</StackLayout>
</ctrl:ShadowFrame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<CollectionView x:Name="NewsListView"
ItemsSource="{Binding News}"
VerticalScrollBarVisibility="Never"
SelectionMode="None">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Vertical"
ItemSpacing="20" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<ctrl:ShadowFrame>
<StackLayout x:DataType="model:News">
<Label Text="{Binding Description}" />
<Label Text="{Binding Date}" />
<Image Source="{Binding Image}" />
</StackLayout>
</ctrl:ShadowFrame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</ScrollView>
</RefreshView>
</ContentPage.Content>
=> Is there a way to achieve this?
Quick reminder that you Shouldn't use Scrollable Elements inside other Scrollable Element, it usually breaks how both work, Quoting:
Xamarin doesn't recommend using the ListView, WebView, or ScrollView
inside a ScrollView. Microsoft Xamarin.Forms Official Documentation
says that ScrollViews should not be nested. In addition, ScrollViews
should not be nested with other controls that provide scrolling, like
ListView and WebView.
And this is what happening:
The ScrollView isn't actually scrolling, the Vertical CollectionView is the one giving the Illusion that the page is scrolling, meaning that the Horizontal one is always on top.
How to fix it?
To fix this, you should remove the Vertical CollectionView and use some kind of Repeater View, this Post will guide you on how to achieve it.
I am developing UWP application, to showing loading process i am using a Custom GIF image as usercontrol. I am adding this GIF image user control to a grid like below.
But while running the GIF it hangs some time..But when i use ProgressRing control it is running perfect.
<Grid
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="ProcessingGrid"
Visibility="{x:Bind VM.IsProcessing ,Mode=TwoWay,Converter={StaticResource BooleanToVisibilityConverter}}">
</Grid>
This is my Usercontrol
<Grid
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.Background>
<SolidColorBrush Color="Black" Opacity="0.3">
</SolidColorBrush>
</Grid.Background>
<Image x:Name="loadingGif" Source="ms-appx:///Assets/GifAssets/ADProcessingIcon.gif"
Width="80">
</Image>
</Grid>
try using "XamlAnimatedGif" library
<page
....
xmlns:gif="using:XamlAnimatedGif"/>
...
<Image x:Name="imgLoading"
gif:AnimationBehavior.SourceUri="/Assets/GifAssets/ADProcessingIcon.gif"/>
...
Image XAML component doesn't work when placed in the listview data template in Xamarin.Forms for Windows Phone 8.1. Image appear fine in Android and iOS.
<ListView x:Name="recipeList" ItemsSource="{Binding Tweets}" HasUnevenRows="true">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout>
<Image Source="{Binding ImageURI"} />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
where ImageURI = "http://some-image-off-the-web.jpg"
Update In UWP the text doesn't even appear! Forget the image, the actual text is invisible. I can see that that each list item is populated using the Visual Studio Live Property Explorer, there is definitely text to display in each list item, its just invisible. I remove the Grid the label is and it works fine. Image still not shown. Do ViewCells not work well in windows?
Take a look at your Image Source in the StackLayout.
<StackLayout>
<Image Source="{Binding ImageURI"} />
</StackLayout>
The quotation marks are not aligned.
How do I set the Panorama App Title of a Page as an Image and not a string of text? I have added:
<phone:Panorama>
<phone:Panorama.Background>
<ImageBrush ImageSource="\Assets\image-logo-small.png"/>
</phone:Panorama.Background>
......
However this sets the entire background as the image selected.
Any idea how I can replace the <phone:Panorama Title="Text"> with an Image?
StackOverflow already has similar case in windows 7, Setting image as Panorama Title for Panorama page in wp7
In our case try these
<phone:Panorama >
<phone:Panorama.TitleTemplate>
<DataTemplate>
<StackPanel>
...........
</StackPanel>
</DataTemplate>
</phone:Panorama.TitleTemplate>
..........................
</phone:Panorama >
The following code successfully places an image within Title section of a Panorama App:
<phone:Panorama>
<phone:Panorama.Title>
<Grid Margin="0,80,0,0">
<Image Source="\images\MyImage.png"
HorizontalAlignment="Center"
Width="400" Height="50" />
</Grid>
</phone:Panorama.Title>
....
Try this, for wp8:
<phone:Panorama.TitleTemplate>
<DataTemplate>
<Grid>
<Image Source="/Assets/logo.png">
</Image>
</Grid>
</DataTemplate>
</phone:Panorama.TitleTemplate>
Have fun!!!