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

Mulitline Xaml button in Windows Phone

Problem:
I was trying to get a button to include multiple lines.  I tried using the declarative syntax in the button

<Button
Content="My Main Title \n Subtitle"/>

This did not work since this is going to render without the formatting implied inline.

Solution:
Really straight forward just add the textbox control into the button control and move on.

<Button
 Command="{Binding MVVMControl}"
 Name="MyFabulousButton">

<TextBlock
TextAlignment="Center"
TextWrapping="Wrap">
First Line
<Linebreak/>
Second Line
</TextBlock>
</Button>






Source
http://stackoverflow.com/questions/1449276/multline-text-in-a-wpf-button

Friday, August 7, 2015

Change Grid/Button Background color through MVVM pattern in Windows Phone

Problem:


Having completed an iPhone app using an MVVMCross core backend.  I need to create the windows phone version UI for the backend.  The iPhone app uses the SegmentControl on a view.  The iPhone app works great and seemlessly with the core.  Now windows phone does not have a segement control per se.  You could simply use a hub/tiles or panorama control templates.  The customer however is very enamored of  the look an feel of the Segment Control.  So it was off too Xaml and blend to build out a similar control.  This I accomplished pretty quickly. 

The issue is the binding to the modelview.  Their is no command property on the grid; however the button control does.  So how to get the interaction to bind with the model view?  Fortunately we have the iValueConverter in the UI layer.  This allows us to bind to properties in the xaml controls.  This combined with model view can allow us to get the functionality to match the segmentcontrol.

Solution:


modelview

private Cirrious.MvvmCross.ViewModels.MvxCommand _myCommand
public ICommand MyCommand
{
             get
            {
                  _myCommand = _myCommand ?? new Cirrious.MvvmCross.ViewModels.MvxCommand(DoMyCommand);
                   return _myCommand;
            }

}

private void DoMyCommand()
{
             ISActive = true;
}


private bool _isActive;

public bool ISActive
{
         get
         { return _isActive;}
         set { _isActive = value;
             RaisePropertyChanged()) => ISActive);
        }

}

view (xaml)

xmlns:phone="clr-namespace:Microsoft.Phone.Controls..."
xmlns:local="clr-namespace:MyNamespace"

<phone:PhoneApplicationPage.Resources>
<local:BrushColorConverter x:Key="ColorConverter" />
</phone:PhoneApplicationPage.Resources>
......

<Grid
Background={Binding ISActive Converter={StaticResource ColorConverter}}
....>
<Button
Background={Binding ISActive Converter={StaticResource ColorConverter}}
Command="{Binding MyCommand}"
.....
/>

</Grid>


(BrushColorConverter.cs (separate class file) in UI project)
 public class ColorConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
        {
            return new SolidColorBrush(Colors.Transparent);
        }
        return System.Convert.ToBoolean(value) ?
            new SolidColorBrush(Colors.Red)
          : new SolidColorBrush(Colors.Transparent);
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}




Source:
  1. http://stackoverflow.com/questions/7329812/change-button-background-color-through-mvvm-pattern-in-wpf
  2. http://www.codeproject.com/Articles/758656/Use-Converters-in-your-Windows-Phone-Apps

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

Thursday, July 30, 2015

Unable to read the project file Sqlite.vcxproj

Problem:

 Working with Peter Huene's sqlite port for use with Windows Phone project.  I need to compile the bits for SQLite for the MVVMCross Sqlite libraries.  The project in nuget has support for Droid and Touch but the windows phone project is incomplete.  I downloaded the bits and attempted to open the C++ project and got this wonderful message:

 Unable to read the project file Sqlite.vcxproj

C:\Program Files\Microsoft SDKs\Windows Phone\v8.0\ExtensionSDKs\SQLite.WP80\3.8.6\DesignTime\Common Configuration\Neutral\SQLite.QP80.props not found

Solution:

This made me wonder and about other people with this problem.  Sure enough several people have had similar issues.  The project file checked into the GitHub for Peter's site.  They all resolve down to the version of the Windows Phone extension libraries for SQLite.  Depending on what version is installed.  I was able to resolve the problem by editing the vcxproj file with notepad.  I corrected the path references from 3.8.6 to 3.8.11 which is the version I have installed.  Easy enough and now it works.



Source:
1.) http://stackoverflow.com/questions/18692632/using-sqlite-for-a-windows-phone-8-app
2.)https://github.com/peterhuene/sqlite-net-wp8/issues/9
3.)http://wp.qmatteoq.com/working-with-sqlite-in-windows-phone-8-a-sqlite-net-version-for-mobile/


Thursday, July 16, 2015

plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite - Unified API

Problem:



I just successfully published the app to the iTunes store.  I had the application written and ready to publish when the wonderful Application Loader refused to load my app to the store!!  Why, because
it was not built to support the Unified API.  Easy fix just use the Xamarin upgrade to Unified Api and voila!  But Unified API is not compatible with MVVMCross SQLite Plugin (v 3.2.2)

Wait, not so fast.  I immediately had problems with the SQLite libraries for MVVMCross. 
This caused me about a week of pain working through all the interdepencies.  I was able to get the latest source code from https://github.com/MvvmCross/MvvmCross-SQLite/issues/39.  Then I built out the bits for support of my project.  I was able to compile and run the app.  It would crash each time I ran and attempted to load the screen which loaded  the sql lite plugin!!!

Error:
plugin not registered for type Cirrious.MvvmCross.Community.Plugins.Sqlite

I wracked my brain as to why the ui failed each time on the sqlite load.  I finally reread the api documentation on the MVVMCross wiki.  It finally hit me when I came across this added requirement for the iOS platform plugin. 



Solution:

You must include a second argument in the bootstrap action for the sqllite plugin.  The bootstrap needs the second argument in the interface constructor for iOS.  If you fail to include it then the path to the Touch plugin then the runtime will not load the plugin and will give you the error.

This is not a problem in Droid or Windows Phone builds.

 
using Cirrious.CrossCore.Plugins; 
using Cirrious.MvvmCross.Community.Plugins.Sqlite; 
using Cirrious.MvvmCross.Community.Plugins.Sqlite.Touch; 


public class SqlitePluginBootstrap 
: MvxLoaderPluginBootstrapAction<Plugins.Sqlite.PluginLoader, Plugins.Sqlite.Touch.Plugin> 
{ }




Source:
  1. https://github.com/MvvmCross/MvvmCross/wiki
  2.  https://github.com/MvvmCross/MvvmCross-SQLite/issues/39
  3. http://stackoverflow.com/questions/30648697/mvvmcross-community-plugin-for-sqlite-with-unified-api 
  4.  http://blog.alectucker.com/post/2015/01/19/sqlite-error-with-xamarinios-unified-api.aspx
  5.  https://bitbucket.org/twincoders/sqlite-net-extensions

ERROR: ERROR ITMS-90047: "Disallowed paths ( "iTunesMetadata.plist" ) found at: MyNewTool.app"

Solution:

For command line or IDE builds with XamarinVS
  1. Ensure "Project Properties -> iOS IPA Options -> Include Artwork in IPA" is not checked. (Or manually set the BuildIpa and IpaIncludeArtwork properties as mentioned above.)
    image
  2. Build the app.
  3. Submit the .ipa file using Application Loader.
or

<Target Name="_CompileITunesMetadata" DependsOnTargets="_DetectSdkLocations;_DetectAppManifest;_GenerateBundleName;_CompileAppManifest">
  <Message Text="Skipping CompileITunesMetadata task to prevent inclusion of iTunesMetadata.plist in the IPA" />
</Target>


Source:
  1. https://forums.xamarin.com/discussion/40388/disallowed-paths-itunesmetadata-plist-found-at-when-submitting-to-app-store/p1
  2. https://discussions.apple.com/thread/6997898?start=0&tstart=0
  3. https://bugzilla.xamarin.com/show_bug.cgi?id=29180#c0