GestureService OnFlick - windows-phone-7

How can I add the GestureService and a handler for the Flick event in code-behind (i.e. not in XAML)?

Firstly, make sure you've added a reference to the Silverlight Toolkit for Windows Phone 7, specifically the Microsoft.Phone.Controls.Toolkit.dll assembly. Then make sure you have an XML namespace reference for the Microsoft.Phone.Controls namespace:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
Then, add the GestureService.GestureListener to the control you want to handle gestures on:
<TextBlock x:Name="test" Text="Test">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="TextBlock_Flick" />
</toolkit:GestureService.GestureListener>
</TextBlock>
Then you just need to implement your logic in the event handler.
Update: The above approach is for using the GestureService in XAML; to use the GestureService in code-behind you use the GetGestureListener method:
var listener = GestureService.GetGestureListener(this.test);
listener.Flick += this.TextBlock_Flick;

Related

Can I pass Android styles in parameters with Xamarin.Forms XAML

Is there a way (without using a renderer) that I can set styling for Android switches in a way like this:
<Switch android:colorControlActivated="#FF00FF"
HorizontalOptions="End" VerticalOptions="Center"
IsToggled="{Binding PbSwitch}" />
No. It is shared logic, you can't use platform spec staff there without abstraction. Why does renderer not suit you?

Navigating between xaml pages using Hyperlink NavigateUri in windows 8 application

In Windows phone 8 application, it is possible to navigate between XAML pages using the hyperlink as shown below
Hyperlink MyLink = new Hyperlink();
MyLink.NavigateUri = new Uri("/Views/SamplePage.xaml?entryId=" + entryId, UriKind.Relative);
I am creating dynamic hyperlinks inside IValueConverter based on the content. I am porting the application to Windows 8 and i could not use the same code, as windows 8 supports only the navigation using the Frame
this.Frame.Navigate(typeof(SamplePage));
Is there any other way, i can use Hyperlinks to navigate between xaml pages in Windows 8 metro applications.
Or is there any way to get the current Frame from within IValueConverter to navigate between the pages?
Sounds like you are navigating in the ValueConverter- I personally would not do that.
Use the Frame object, create your own abstraction as a service, or use behaviors (which you of course can use converters with)
<Grid x:Name="grid5" Grid.Row="1" Grid.Column="2" Background="Purple">
<TextBlock x:Name="TextBox" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="45" Text="Navigation with param" Margin="0,165,3,165"/>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:NavigateToPageAction TargetPage="Behaviors_And_Triggers.NewPage" Parameter="{Binding ElementName=TextBox,Path=Text}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Grid>
Dont forget to add the Behaviors SDK extension (Add Reference => Extensions => Behaviors) and namespace:
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
Note: Behaviors_And_Triggers.NewPage => NewPage is the name of the page!

Detecting and Implementing Scrollbar Style in Window 8/RT Application

I am developing a Custom Control to be placed inside a ScrollViewer, I have Custom coded a generic.xaml for applying visual style for the Scrollviewer.
<ScrollBar x:Name="VerticalScrollBar"
Grid.Row="0"
Grid.Column="1"
Width="18"
Margin="0,-1,-1,-1"
IndicatorMode="TouchIndicator"
IsTabStop="False"
Maximum="{TemplateBinding ScrollableHeight}"
The Problem I am facing is, I need to set the IndicatorMode to TouchIndicator/MouseIndicator based on whether the user is using Touch Devices or not.
Is there a way to do it?
Thanks
Arun Selva Kumar. B
Used Visual State Manager to achieve the requirement.

Microsoft.Phone.Controls.Toolkit ListPicker throws XamlParseException

After being advised that the native ComboBox was not the way to go I was told to look at the Silverlight Toolkit ListPicker. So I did and have got a problem.
I opened a new project and pulled a new ListPicker onto the MainPage. The ListPicker looks like:
<toolkit:ListPicker x:Name="Result">
<toolkit:ListPickerItem Content="Win" />
<toolkit:ListPickerItem Content="Place" />
<toolkit:ListPickerItem Content="Lose" />
</toolkit:ListPicker>
When trying to run this I get an XamlParseException with InnerException of InvalidProgramException. All I did was drag the control on, and add some ListPickerItem. Removing the items still results in the error, removing the ListPicker control completely allows the page to be shown with no error.
I'm sure I've missed something, but any documentation I have read seems to point towards this markup being fine, including http://windowsphonegeek.com/articles/listpicker-for-wp7-in-depth
I can provide any other info required.
ListPickerItem is a class used internally by the ListPicker and should not be used directly.
If you just want to add a list of items, you can use strings to do it, like this:
Add a new namespace on top of the Page to access the String class:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then, just change the ListPicker code to this:
<toolkit:ListPicker>
<sys:String>Win</sys:String>
<sys:String>Place</sys:String>
<sys:String>Lose</sys:String>
</toolkit:ListPicker>
The problem was that the wrong dlls had been registered, i.e. 7 and not 7.1. I had to uninstall and reinstall to get it to update correctly and it worked.

Windows phone ads not working

I am trying to integrate ads into a already successful deployed app. However no matter what I do, I cannot seem to get the ads working. I have tried using both the code version and the drag n' drop gui version. Neither of which I can get to work.
This is what I see: When it starts up it may flash for a split second white, where the ad is supposed to be, but none the less, no adds. It recognizes that it is where I place it, when I place it over a button, the button becomes unclickable. All being said, no default "microsoft advertising" image pops up. I have installed the ad SDK and have successfully been able to make the ads display in other project with ease.
What gives? This is very simple page and I cannot figure out what is wrong. It also seems that I cannot place an ad on any of the other pages either... I do have the Microsoft.Advertising.Mobile and Microsoft.Advertising. Mobile.UI included in the project and my internet is working (I have an project open at the same time with ads and it works)
<phone:PhoneApplicationPage
x:Class="AppName.AdPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
xmlns:my="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Margin="12,17,12,28">
<TextBlock x:Name="PageTitle" Text="Thank You!" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Width="334" />
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0" Height="569" VerticalAlignment="Top">
<Button Content="Ok" Height="72" HorizontalAlignment="Center" Margin="0,428,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Advertising.Mobile.UI;
using Microsoft.Advertising.Mobile;
namespace Stickey_Note_v._1
{
public partial class AdPage : PhoneApplicationPage
{
public AdPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
}
}
I had the same issue and wrote a blog post about it. Here's the important stuff:
The symptoms of a problem with the SDK's AdControl seem to be pretty consistent: The page loads, the control flickers briefly, showing the hint of a 1 pixel frame, and then, poof. It collapses into nothingness, leaving only a black hole of dispair.
In theory, setting up the AdControl is simple. The documentation from Microsoft outlines the basics:
Download and install the Microsoft Advertising SDK.
Add a reference to Microsoft.Advertising.Mobile.UI.
Drag the control onto the page in the Visual Studio designer.
Set the AdUnitId and ApplicationId properties to either test values or actual live values, which you can obtain from Microsoft pubCenter.
But it couldn't be that easy. I followed the documentation carefully, but nothing was working. I couldn't even get test ads to show up, which seemed really weird. I even reverted to an older version of my app (yay source control!) and dropped in the new .dll. Failure.
Finally, I found a clue in an obscure forum post.
The Microsoft documentation neglects to mention several important details. You need to pay particular attention to the following if you're upgrading an existing project to the Mango ad SDK, as I was:
You must specify a height and width for the AdControl. Failing to specify the Height and Width attributes, or setting them to auto, will cause tears of frustration. I'd recommend 80 pixels high and 480 pixels wide, as that's the native size of the ads that Microsoft serves up.
It seems that you can't have two AdControls on the same page, or at least not in the same parent element. The second one will collapse. There might be a way around this, but I discovered it while building my demo app and didn't care to pursue a solution.
You must must must specify certain capabilities in your WMAppManifest.xml file. Since I was upgrading my app, I didn't have some of the newer capabilities declared. The one that was causing all the trouble was ID_CAP_IDENTITY_USER. The following capabilities are all required for the control to function correctly:
<Capabilities>
<Capability Name="ID_CAP_IDENTITY_USER"/>
<Capability Name="ID_CAP_MEDIALIB"/>
<Capability Name="ID_CAP_NETWORKING"/>
<Capability Name="ID_CAP_PHONEDIALER"/>
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
</Capabilities>
Hope that helps!
I think your problem could come from (if you didn't remove it for posting it here):
<my:AdControl AdUnitId="Image480_80" ApplicationId="test_client" Height="80" HorizontalAlignment="Left" Margin="-12,458,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" />
</Grid>
You have to use AdUnitId and ApplicationId which you get from pubCenter.
One more think to note for those still struggling
xmlns:ads="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"
<ads:AdControl Height="80"
Width="480"
AdUnitId="Image480_80"
ApplicationId="test_client" />
As in example. Declaring ads and the namespace is super important.
In my project i just inserted the adcontrol part alt + enter for resharper to do the rest of the work which he didnt. He replaces ads with UI and there was no error compilation still the ads wouldn't show. When i declared ads myself and changed the adcontrol namespace. Everything worked fine.

Resources