Manipulation events in wp7 - windows-phone-7

I am developing Windows phone 7 application, I need to do a slide show like application. I have the File[] when I swiping left or right the previous or next Image should show. how to Do it? I think it is possible through Manipulation events. but how to do this , I dont know Can u explain this?

The simplest way to create this effect woudl be something like this:
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<StackPanel Orientation="Horizontal">
<Image Source="A.png" />
<Image Source="B.png" />
<Image Source="C.png" />
<Image Source="D.png" />
</StackPanel>
</ScrollViewer>
Although you could add the images through code.
If you want something more complex in your animation or need control over how an image can be interacted with you may want to do something different.
Before trying to use manipulations you may be able to use the Flick event from the toolkit which may make what you're trying to achieve easier.
It will all depend on what you're trying to do. Your question isn't explicitly clear.
See also how to get swipe in windows phone 7

Related

XAMARIN Forms - why the same form looks different on iOS and Android

I have decided to try Xamarin Forms, because I thought that I can make one design for all platforms or at least Android and iOS.
However a simple form like:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:app91="clr-namespace:App9;assembly=MasterDetail.Android"
x:Class="MasterDetail.CompetitorsListPage"
>
<StackLayout>
<Label Text="{Binding CurrentEvent.Name}"></Label>
<StackLayout Orientation="Horizontal">
<Button Text="By Place" Clicked="Button_OnClickedByPlace"></Button>
<Button Text="By Number" Clicked="Button_OnClickedByNumber"></Button>
<Button Text="By Rating" Clicked="Button_OnClickedByRating"></Button>
<Button Text="Change Event" Clicked="Button_OnClickedChangeEvent"></Button>
</StackLayout>
<ScrollView>
<ListView x:Name="couples" ItemSelected="Comps_OnItemSelected" ItemTapped="Couples_OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Round}"></Label>
<Label Text="{Binding Pos, StringFormat='({0}).'}"></Label>
<Label Text="{Binding Name}"></Label>
<Label Text="{Binding StartingNumber}" ></Label>
<Label Text="{Binding OldRating, StringFormat=' [{0}]'}"></Label>
<!--<Label Text="{Binding NewRating, StringFormat=' {0} ]'}"></Label>-->
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</StackLayout>
</ContentPage>
Looks completely different on Android and iOS. I do not mind colours, but font size? I do not set font anywhere in the code or xaml.
Any idea what am I doing wrong?
Here it is a picture showing both versions:
This is by design. Forms is intended to provide a native experience on each platform by using their respective UI standards. Android has a different default color scheme than iOS. iOS default buttons look different than Android.
You can override the default fonts, sizes, colors, etc if you like in order to provide a more consistent UI. Xamarin has also introduced Themes for Forms which help you provide a consistent UI between platforms.
Because Android has variety of screen sizes and different screen DPI as compared to standard dpi and font sizes across iOS devices, it is not possible to create same look. But you can certainly change Theme in the MainActivity of your Droid project and increase font size as per your convenience. Beware that your theme's font size may be too big for small devices and too small for big devices. You can add scaling factor for font size in your theme, but I have not been very successful, instead, I tried to design a UI that will automatically fit for the best.
As per Xamarin Evolve 2016, some questions were raised regarding font sizes, they said it is difficult, but they are trying to make some unified font sizing.
Although Xamarin.Forms has everything in Xaml and C#, you still need to use iOS assets and Android resources to customize look and feel.
For me, #Jason's answer and comments from #Egg and #Bill Reiss are spot-on.
Meanwhile, so often clients request "same font size" across platforms that something like this finds its way into base Styles or Theme to account for what seems to be "natively smaller" fonts on Android:
<OnPlatform x:TypeArguments="Font">
<OnPlatform.iOS>Bold,Medium</OnPlatform.iOS>
<OnPlatform.Android>Bold,Large</OnPlatform.Android>
<OnPlatform.WinPhone>Bold,Medium</OnPlatform.WinPhone>
</OnPlatform>
Something similar can also be expressed in code at or near app startup, for example as a base Label font added to global Styles dictionary.
Just wanted to give a concrete example of what others above alluded to.
Strange behavior on iOS - as you can see those are labels in StackLayout, while in Android they behave OK, in iOS second and third label behave more lithe they were in some kind of grid rather than stack –
You have put 5 labels in a horizontal stack, and haven't changed the layout options on any of them. This will 'stack' all 5 labels next to each other, then size them based on the amount of text to be displayed. There is not enough horizontal space to accommodate all of the text, so the labels are wrapping vertically. The longest labels show the most wrapping, but as they get longer other labels wrap as well, which is why the Pos and OldRating data raps in some labels. When I'm working out layouts like this I often add different background colors to each control so I can see how they are laying out.
There are different ways to solve this depending on your desired result. If you want the entire line of text to wrap you can concatenate the data behind the scenes and add it as one label. If you want the name to wrap and the other data to display without wrapping you can set WidthRequests on the labels.

how to show a zoomable image in a windows 8 (WinRT) app?

Is it possible to put a image into a control in WinRT and then let the user zoom in and out etc?
Yes!
The easiest possible way is to put it inside a scrollviewer. You can zoom in and out whatever you like that way!
<ScrollViewer MaxZoomFactor="3"
MinZoomFactor="0.5"
ZoomMode="Enabled">
<Image Source="/Assets/logo.png" Width="200" Height="200"/>
</ScrollViewer>

WinRT zoom of image control by code if possible

I am working at a WinRT application that implies some manipulations of an image at a WriteableBitmap level. On my page, I have ofcourse an image that shows the processing results. My objective now, is slightly different though, I would like to know if there is any way I could acces through code the built-in zoom in/out that could be achieved through pinch mode if on touch device on control + mouse wheel if on PC.
Here's a bit of my code where I've got the image :
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<Image Grid.Row="0" x:Name="ImagePanel" Stretch="Uniform" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</ScrollViewer>
I am asking this in case anyone might know if this can be achieved only because the zoom is very optimized and can be extremely useful :)
Thank you, any help or suggestions are greatly appreciated.
The ScrollViewer has a ZoomFactor property and a ZoomToFactor() method you can use.

wp7 Bing map displays in design view but is just black on emulator and phone-used to work perfectly

as you can see the pin "myTent" is loaded onto the map but it is not displayed.
I took a break from this project for a few weeks but changed nothing relative to the map. Saw somewhere that they replaced the token system with keys but I already have a key so shouldn't affect me?? Do keys expire?I don't think they do.
map is set up normally:
<Grid x:Name="ContentPanel" Margin="12,171,12,12" Grid.RowSpan="2">
<Button Content="MyTent" Height="72" HorizontalAlignment="Left" Margin="63,507,0,0" Name="myTentButton" VerticalAlignment="Top" Width="160" Click="myTentButton_Click" />
<Button Content="Find Me" Height="72" HorizontalAlignment="Left" Margin="209,507,0,0" Name="findMeButton" VerticalAlignment="Top" Width="160" Click="findMeButton_Click" />
<my:Map Height="523" HorizontalAlignment="Left" Margin="6,6,0,0" Name="map1" VerticalAlignment="Top" Width="444" CredentialsProvider="------------myKEY--------------" />
</Grid>
Any thoughts on why this is happening now when it worked before?? or other tags which may attract right attention, not sure where the fault is as there is no errors
many thanks,
MH
It looks to me like the Map application itself is working ok, it's just that it hasn't displayed the map tiles that should be present in the background. If this is the case, here's a couple of possible suggestions to check, which are not clear from the code snippet you've provided:
Make sure you're specifying a valid map style (Aerial, Road, Birdseye etc.)?
Make sure that the location on which the map is centred has imagery available for the zoom level at which the map is being displayed. (i.e. some high-resolution imagery at zoom level 19 is not available at all locations)
Make sure that your phone has a valid internet connection over which it can connect to the Bing Maps servers in order to retrieve the necessary tiles.

Windows Phone 7 Image Button

I need to create an Image Button for my application like web-oriented style.
I have an image 20x20 pixel and want an image button with the same dimension of the image.
I tried to set this inside my xaml but it doesn't work:
<Button Grid.Row="0" Margin="0" Padding="0" Click="AddtoFavorite_Click" Width="20" Height="20" VerticalAlignment="Top" HorizontalAlignment="Right">
<Button.Content>
<Image Source="/MyNamespace;component/images/star_yellow.png" Margin="0" Width="20" Height="20" />
</Button.Content>
</Button>
What is wrong?
SOLUTION
I found the best solution is:
<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image>
Thanks to all!
I don't see particular errors in your code but I don't have the tools right now to test it ans see why it fails.
However you can create a VisualBrush with your image and use it as background for your Button:
<Button>
<Button.Background>
<ImageBrush ImageSource="xyz.png"/>
</Button.Background>
</Button>
Most Backgrounds are of type Brush, so you can use SolidColorBrush, LinearGradientBrush, ImageBrush, etc. You are not limited to colors.
I think the best solution is the following:
<Button ...>
<Button.Template>
<ControlTemplate>
<Image .... />
</ControlTemplate>
</Button.Template>
</Button>
Using manipulation started will result in subtly non-standard behaviour. On most buttons if you click on it but then drag off, the button click will not fire. However, if you use ManipulationStarted it will fire immediately.
The best way to manage these design time considerations is to use Expression Blend. In blend you can right click on the button and edit the template through the design tools, which makes knowing how to edit the xaml less important. It's really worth the effort to learn to use Blend.
This is old but I thought I would offer what I thought was a better solution here. Some of these solutions want you to replace the button with an image, or the background with an imagebrush. That's fine except it also surrounds the image with the normal button style, a black or white box (depending on your theme).
This solution lets you use an image as the button itself while maintaining the complete fidelity of a button but without having to subclass an object like the link by SilverGeek.
First, create a new style (either in your App.xaml or your page resources)
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Image x:Name="StartButtonImage" Source="/Images/YourImageFile.png"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content=""/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
Now, just create a button anywhere using that style:
<Button Style={StaticResource ImageButtonStyle}/>
And add click events or whatever else you want. The button will take on the entire style of the image.
Maybe you will be interested in this article:
http://silvergeek.net/2011/01/14/imagebutton-control-for-win-phone-7/
The Button control can take most controls as its content (not just text), so you don't need an "image button" - instead, you simply need to put an Image control inside your Button like so:
<Button>
<Image Source="http://www.richmondwiki.org/images/search-button.png"></Image>
</Button>
This approach (as opposed to using an ImageBrush for the Button background) means that you don't have to worry about or hardcode the sizes of the Image/Button - WP7 will handle this for you.
Using the provided Button control instead of hooking into the manipulation events is recommended, so that you won't have to worry about things like having appropriate margins for touch targets, etc.
You can set your image as the background for the button, or if you want to do it as content, in theory it should work inside a stackpanel.
You don't even need to use a Button.
You can hook the MouseLeftButtonUp event on the Image control.
<Image
Source='blue02.png'
Width='26'
Height='26'
Margin='5'
MouseLeftButtonUp='Image_MouseLeftButtonUp' />

Resources