Showing posts with label WP8. Show all posts
Showing posts with label WP8. Show all posts

Monday, August 10, 2015

How to center the hint in a WP8 Toolkit PhoneTextBox


Problem:
I'm using a WP8 toolkit PhoneTextBox control. I'd like the hint to be set top and left. The following code should work but it is like the HintCustom Style is begin ignored!

<toolkit:PhoneTextBox Name="textLongUrl" TextWrapping="Wrap" InputScope="Url" Height="150" MaxLength="250" DisplayedMaxLength="250" LengthIndicatorVisible="True" FontSize="20" Hint="Type or paste URL" HintStyle="{StaticResource HintCustomStyle}" ActionIcon="Assets\Images\icon-button-32.png" ActionIconTapped="textLongUrl_ActionIconTapped" KeyDown="textLongUrl_KeyDown" />


And here's the hint style I'm using:
<Style TargetType="ContentControl" x:Key="HintCustomStyle">
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="FontSize" Value="36"/>
</Style>


Solution:

The issue is the toolkit itself.  The PhoneTextBox is predefined and that is what needs to overridden.  The Hint style I had created was being overridded each time the screen loaded by the PhoneTextBox.
This means that I needed to override the PhoneTextBox itself.

Do the following:

Open the project in blend and Right click on the PhoneTextBox and select Style > Edit a copy to edit the template. Find the Border named "HintBorder" and expand it to see "HintContent" and "ContentElement" ContentControls. "HintBorder" is the one you want. Select it and from the property panel set the HorizontalAlignment to Left and VerticalAlignment to Top, that should do it. Your Hint Text is vertically aligned to the top and left adjusted. I also added some Fontsize specifics for my app.




Source:
http://stackoverflow.com/questions/20778159/how-to-center-the-hint-in-a-wp8-toolkit-phonetextbox

Wednesday, August 5, 2015

Windows Phone disable status bar

Problem:
Trying to fix a problem on a Windows Phone Silverlight 8.1 app today.  The app starts with a splash screen and do to some extra processing it has an extended screen which simply displays the same screen again.  The issue arises when the splash screen which the OS handles switches over to the first view which also displays the same splash screen image.  Due to the status bar displaying on the first screen the image shifts down.  This leads the image dropping down vice staying in place.  The transition from needs to be smooth without any resizing of the image.  The solution seems to be simply to hide the status bar on that screen.  But how to do it?

Solution:

Windows Phone 8 / Windows Phone 8/8.1 Silverlight


Code behind in ExtendedSplashScreenView.xaml.cs:

public partial class ExtendedSplashScreenView(): MvxPhonePage
{
  InitializeComponent();
  Loaded += MainPage_Loaded;
}

private void MainPage_Loaded(object sender, RoutedEventArgs events)
{
  SystemTray.IsVisible = false;
}


Windows Phone 8.1

Code behind in ExtendedSplashScreenView.xaml.cs:

public partial class ExtendedSplashScreenView(): MvxPhonePage

{
  // Get the Status bar for the Current Window.
  Windows.UI.ViewManagement.StatusBar statusBar =     Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
  // Hides the status bar
  await statusBar.HideAsync();
}


Source:
1.) Windows Phone 8 / Silverlight
  • http://stackoverflow.com/questions/6674627/how-to-hide-the-status-bar-in-wp7-silverlight
2.) Windows Phone 8.1
  • http://blogs.msdn.com/b/johnkenn/archive/2014/04/16/hiding-the-status-bar-in-windows-phone-8-1-apps-or-not.aspx
  •  http://developerpublish.com/how-to-hide-status-bar-in-windows-phone-8-1-xaml-app/
  •  http://blogs.msdn.com/b/amar/archive/2014/05/12/status-bar-in-windows-phone-8-1.aspx

Tuesday, August 12, 2014

Adding listener to MessageBox ok button in Windows Phone

I was updating my phone application and needed to provide a response to a user prompt. This is called adding a listener to the message box. This is easily done by adding the following code block into the location where you will be running the messagebox. This SDK supported messagebox control only supports the OK and Cancel buttons. If you want more control then you will need to use the XNAFramework messagebox which supports more customization. Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBoxResult result = MessageBox.Show("Show next message?", "Question", MessageBoxButton.OKCancel); // code after user click if (result == MessageBoxResult.OK) MessageBox.Show("Yeah"); }); Source: http://stackoverflow.com/questions/21773730/adding-listener-to-messagebox-ok-button-in-windows-phone

Friday, April 4, 2014

Windows Phone 8 Emulator connecting to localhost...

Problem:

Well this getting the Windows Phone emulator to work with a web service running on localhost turned out to be more work then I thought.  There are a multitude of blogs and postings to walk you through the process. Each implementation is slightly different and my issues may be unique to my box.  That said I did want to document what caused me so many issues. 

Solution:

1 – Bind your application to your public IP address

Normally when you run an application in IIS Express, it’s only accessible on http://localhost:<port>.
In order to access it from another machine, it needs to be bound to your public IP address as well.
Open D:\Users\<YourName>\Documents\IISExpress\config\applicationhost.config and find your site.

<site name="Test.Web" id="2">   
<application path="/">       
<virtualDirectory path="/" physicalPath="C:\Users\Jeff\Test\Test.Web" />   
</application>   
<bindings>       
<binding protocol="http" bindingInformation="*:39142:localhost" />   
</bindings>
</site>

In <bindings>, add another row:
<binding protocol="http" bindingInformation="*:39142:169.254.80.80" /> (But with your IP, and port number, of course)

2 - Allow incoming connections

If you’re running Windows 7/8, pretty much all incoming connections are locked down, so you need to specifically allow incoming connections to your application. First, start an administrative command prompt. Second, run these commands, replacing 169.254.80.80:39142 with whatever IP and port you are using:

> netsh http add urlacl url=http://169.254.80.80:39142/ user=everyone
This just tells http.sys that it’s ok to talk to this url.

> netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=39142 profile=private remoteip=localsubnet action=allow
This adds a rule in the Windows Firewall, allowing incoming connections to port 39142 for computers on your local subnet.


Key learnings:

1.) Command prompt
2.) ipconfig
Results may vary:

Ethernet adapter vEthernet (Internal Ethernet Port Windows Phone Emulator Internal Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c0fc:ebf2:755d:4a03%14
   IPv4 Address. . . . . . . . . . . : 169.254.80.80
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

3.) Emulator IP is 169.254.80.80

4.)Cut and paste line to add a second binding row.
binding ip needs to be exactly what the IP for the emulator is:

bingingInformation="*:<port>:<ip address>"

Sample:
bindingInformation="*:39142:169.254.80.80"

5.)Allow incoming connections
Open cmd as admin
>netsh http add urlacl url=http://169.254.80.80:39142/ user=everyone

6.)Adds rule in the Windows Firewall, allowing incoming connections to port 39142 for computers on your local subnet.
 Open cmd as admin
>netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=39142 profile=private remoteip=localsubnet action=allow

Addendum:
 Debugging was failing to connect on my VS 2013 build.  I realized that I was having firewall issues.
I started by turning off all the firewalls to determine if this was the issue.  Once the firewall was down I was able to connect from the emulator to localhost.  I then modified the netsh command.

Change the profile to public on the firewall connection.

> netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=public remoteip=localsubnet action=allow



Research How tos:

MVC Sample

http://blog.anthonybaker.me/2013/06/how-to-connect-to-local-web-services.html

Microsoft has drafted a how to guide using a wcf web service
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580.aspx

Robert McMurray has a great guide on connecting the emulator to a Web API project in Visual Studio.
http://blogs.iis.net/robert_mcmurray/archive/2013/08/20/connecting-the-windows-phone-8-emulator-to-web-api-applications-on-a-local-computer.aspx

Johan's succint post gave the key steps in the process
http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-computer

Tip using fiddler
You can install fiddler and go through the instruction on how to configure fiddler for windows emulator.
This article worked just fine for me:http://blogs.msdn.com/b/wsdevsol/archive/2013/06/05/configure-the-windows-phone-8-emulator-to-work-with-fiddler.aspx
One the configuration is done, emulator will automatically use fiddler as a proxy server and you localhost should work just fine from emulator too.
Remember to start fiddler before starting the emulator to route the traffic, otherwise it wont work. You will also be able to monitor http/https requests made by windows emulator.

Source:
http://stackoverflow.com/questions/13149304/windows-phone-8-emulator-access-localhost