Responsive design on Windows phones - windows

I am fairly new to an app Development. One of the things that I am struggling with is to make sure my app looks the same on devices with different screen sizes.
Here is the logic that I use:
public MainPage()
{
this.InitializeComponent();
placeUI();
}
The placeUI() method is a method where I measure the width and the height of the screen. From there for instance if I need to place my component 10% from the left I just multiply its x position on a coordinate by 0.1.
My question is - if its the standard way of making UI responsive to diffirent screen sizes or is there an easier way? Thank you!

See Define page layouts with XAML for an several techniques to use for responsive design. That page targets Universal Windows apps (Windows 10), but other than the RelativePanel and AdaptiveTriggers everything applies to Windows Phone 8.1 Runtime apps as well.
If you just want a lightly responsive design such as your example of placing an item at a constant 10% from the edge then you can set your layout in a Grid control with a column set to take 10% of the Window:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"></ColumnDefinition>
<ColumnDefinition Width="9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1">This is 10% from the left</TextBlock>
</Grid>
While this seems like a lot for a single item, it usually works out well for a typical layout with multiple elements.
For busier designs with many more controls you may want to move them around based on the size of the screen. 50% of a wide screen may be plenty for a given chunk of text while 50% of a narrow screen may be much too small for the same text. The app may want to switch from a horizontal layout on the wide screen to a vertical layout on narrow screens. The app can use visual states to move controls around or switch the controls completely (e.g. a GridView for wide screens and a ListView for narrow screens, both bound to the same underlying data).

Related

Xamarin Forms: Footer image is not displaying fully

In my login UI, I have a footer image, which is showing perfectly in small devices. But on big screen devices (mainly on iPad) it is not showing fully.
I tried all Aspect property of Image, but not worked.
Screenshot:
I try a lot to fix this but didn't get a solution.
Attaching the LoginPage.xaml file with this question. Please suggest a solution for this issue. :)
Make sure (in the iOS project -> Assets) your image set has 3 different sizes xxx.png,xxx.png#2x and xxx.png#3x .
Which image will be used for your app? That depends on the device your app is viewed on. Higher resolution devices (larger and newer devices) have more pixels on their screens. Thus they need higher resolution images to display properly without any blurring.
If you don’t supply the higher resolution (#2x or #3x) images, your app will automatically try to scale the #1x image up. This is not good and can result in a distorted or blurry image!
Based on the file you linked in the comments, I think it would suffice to remove the bottom StackLayout wrapping the Image, and instead put Grid.Row="1" & VerticalOptions="End" to the bottom Image.
Please update your question with the relevant code to make the question and answers more helpful to others.
Remove latest StackLayout with image and add it after StackLayout with Grid.Row="1" like this
<Grid Grid.Row="1"
BackgroundColor="#c0eefb">
<Image
Source="ic_footer_image_xx.png"
Aspect="AspectFill"
HorizontalOptions="FillAndExpand"/>
</Grid>

Creating Custom label background in Xamarin Forms

I am developing in Xamarin forms, and I have a Label that can contain a varying amount of text.
The platforms I use in forms are primarily: Android and UWP (no need for iOS ATM).
I want to give this label a background that is not rectangular and that is something more like this: (chat/message bubble style)
I have read about some possible solutions but I'm confused from all the options that are available.
From what I understand of my research around this and from my work with other platforms there are basically two options:
Set an image background.
Use Custom graphic controls to create the shape I want.
I'm not sure how to implement any of these options in Xamarin Forms, I'll be glad to get some help.
The easy solution would be to host the Label inside a View and set have an Image behind the label:
<Grid>
<Image Source="message_background.png">
<Label Text="{Binding Message}">
</Grid>
This is not very performant if you're going to have a lot of these on screen. The best solution would then be to use a custom renderer for each platform an implement it natively. This would give much better performance much more flexibility. It's more maintenance and initial work though.
You can read up on custom renderers here

Autolayout just not working for every screen size

My app is a game and the menus have many labels and buttons and I cannot get all of the different screen sizes(iPhone 4/5/6/6+) to look acceptable from the same set of constraints.
Is there a way that you use to synchronize all the views together to look the same on all different screen sizes?
The project is locked to only portrait so I don't need to consider rotation.
For Autolayout, you
Consider the screen sizes you want to support.
Which view/buttons/labels/imageview etc you want to remain fixed while in
different screen size.
Which view/buttons/labels/imageview etc can be scaled to fit the screen.
Now if by scaling the things you can fit on the screen then you are good to go. But if you still can't find way then you would probably need to you use scrollview and and add a UIView (let's call it content view) to it put your all stuff in it and constraint them vertically all the way from top to bottom.This video can help you if you want to use scrollview
https://www.youtube.com/watch?v=UnQsFlMGDsI

Is there a way to improve Image memory usage for Image controls using the same images?

In a WP7 game I'm building my Enemy classes are wrapped in an EnemyControl.
The Enemy Control uses a spritesheet of all the different animation states for that enemy type. There are only 4 images which I statically cache the bitmaps for.
The problem I have is that despite both the image being cached (BitmapImage statically and CacheMode="BitmapCache"), when the Image is loaded by the control it adds approximately 2 meg of Texture/System memory per control.
This is a significant problem as it limits the number of enemies I can conceivably have on screen.
Does anyone have any ideas how I could improve this situation? or otherwise solve it?
Here's the xaml if interested:
<Canvas x:Name="canEnemyControl">
<Canvas.RenderTransform>
<TranslateTransform x:Name="enemyControlTransform" X="0"/>
</Canvas.RenderTransform>
<Canvas.Clip>
<RectangleGeometry x:Name="clipGeometry" Rect="0,0,60,60" />
</Canvas.Clip>
<Image x:Name="imgEnemy" Stretch="None" CacheMode="BitmapCache" >
<Image.RenderTransform>
<TranslateTransform x:Name="enemyImageTransform" X="0" Y="0" />
</Image.RenderTransform>
</Image>
</Canvas>
I don't think your implementation will scale because I don't think the multiple Image elements know to share the same bitmap cache.
Solution: CompositionTarget.Rendering and WriteableBitmapEx
One possible solution would be to use CompositionTarget.Rendering for rendering like in my answer here. This fires an event before the screen is updated so you can do your own drawing. I believe this is how Krashlander and some other Silverlight games work (though I think he may have switched over to XNA in later versions).
Then I think that you can use WriteableBitmapEx to use one instance of your source image to draw it into multiple places on a buffer. You should scale much better because you have your buffer the size of your screen/viewport, and you have your one copy of each image. The memory requirements for displaying 1 enemy and 1000 should be the same.
I will add a disclaimer that I haven't tried this exact approach, but I do use CompositionTarget.Rendering in one of my apps for smooth screen updates.

How is/can the WP7 Office Hub panorama header markup be created?

WP7 Office hub panorama header looks like this:
What is it?
one solid image
two images (one for logo, one for "microsoft Office")
all vector elements
The answer interests me only because I know how to achieve this only in the first two cases.
Basically I need to create a TextBlock in PanoramaHeaderTemplate, that would be like this:
<TextBlock Foreground="Black"><Run Text="smallBold" FontWeight="Bold"/><Run Text="Normal"></TextBlock>
So the resulting panorama should have a look:
If I use FontWeight directive in the PanoramaHeaderTemplate - it for some reason has no effect.
If I use PanoramaTitleTemplate, I get the controllable text weight, but I have a panorama header element appear for some reason, that only displays a x:Key element name of the PanoramaItem, that results in an appearance of a header I don't need at all. This happens even if I don't define the panorama header.
So which is the correct way to achieve the look on the Panorama "upper element", whether it is Title or Header, that is shown on the smallBold.Normal figure?
I don't know what Office uses but it's irrelevant because, as a native app, it wasn't created with Silverlight.
You can create the same effect by changing the Panorama.TitleTemplate to contain whatever you want (TextBlocks, images, etc.). You may also have to adjust the defautl Style applied to the template to set a Height and Width for the PanningTitleLayer.
It's an image, straight across the panorama. It's very simple, as the panorama view was set up to display long images to support a better scrolling feel for the user.
So i would look into using images, as it's easier to achieve, what you are trying to do, with images, rather than a background image.
Some useful related questions/articles:
May Help, StackOverflow
UI Concepts For Windows Phone 7
How I made the ‘myChannel9' wp7 app
Capturing Windows Phone 7 Panorama Images

Resources