MyAdviceWriter ...

imageXamarin.Forms is an attractive option when building cross platform apps, but for an old XAML developer like myself it can be a challenge to get the nuances of the grammar and syntax right. For Windows I’ve depended on tools like Blend and Visual Studio Intellisense to help me understand what’s possible. Moving to Xamarin XAML is sometimes tedious because while I can use the intellisense from the C# code behind file it’s not there yet in a designer. While there’s some posts out there that compare and contrast how to move to Xamarin XAML from Microsoft XAML (like this one from TCPWare by Nicolò Carandini), I still wasn’t finding what I was looking for. This post is an attempt to iterate thru some of the core proprties of interest for many of the controls I use, and to catalog them here for current and future reference.

1/3/2015 : Update, added more controls to list -

Technorati Tags:

First some common properties – Some common properties to most controls include:

  • x:Name : The control name that can be used to reference the control from code
  • AnchorX, AnchorY : Positions control within the layout
  • HeightRequest, WidthRequest : The requested size of the control if the layout allows
  • MinimumHeightRequest, MinimumWidthRequest : The minimum size allowed
  • HorizontalOptions, VerticalOptions : Layout options for the control, include values Start, End, Fill, Center, StartAndExpand, EndAndExpand, CenterAndExpand
  • BackgroundColor : Color of background
  • Rotation, RotationX, RotationY : Rotation properties for rendering control
  • Scale : Scale value

Label - Displays text on a page.

  • XAlign, YAlign : Text alignment property…values include TextAlignment.Start, TextAlignment.Center, TextAlignment.End
  • TextColor : Color of text and background…can be named color
  • Font : Attributes of the font, such as Bold, Italic, Large, Medium, Small, Micro, 
  • LineBreakMode : Used to determine label’s text wrap properties. Values include CharacterWrap, NoWrap, WordWrap, HeadTruncation, MiddleTruncation, TailTruncation

TextCell - Displays text and detail subtext in a single control

  • Text : The main text to display
  • TextColor : Primary color of the text
  • Detail : Subtext displayed below main text
  • DetailColor : Color of secondary text

imageimageimageBoxView - Similar to Rectangle in Windows XAML. Used to display a box with some color on a page.

  • Color : Color of box
  • Opacity : Value of opacity…
  • IsEnabled, IsFocused : properties of Box

Entry - Similar to TextBox in Windows XAML. Used to get input from user.

  • TextColor : Color of text and background…can be named color
  • IsEnabled, IsFocused, IsPassword, IsVisible : Values that drive entry behaviors
  • InputTransparent : Determines whether to show input
  • Keyboard : Type of keyboard to show, possible values include Chat, Default, Email, Numeric, Telephone, Text, Url
  • Placeholder : Text to display when there is no value entered…displayed in grayed out mode
  • Text : Value of control

Image - Display an image. Includes common properties and:

  • Aspect : Scaling of image…stretch or fill. Values include Fill, AspectFill, AspectFit
  • IsEnabled, IsFocused, IsLoading, IsOpaque, IsVisible : Drive behaviors of image control
  • Source: This is where the image is sourced from…can be local resource or online.

ImageCell Displays an image and a TextCell

  • ImageSource
  • Text, TextColor
  • Detail, DetailColor
  • IsEnabled

Button - Used to trigger event processing in response to user’s actions

  • BorderColor, BorderRadius, BorderWidth : Values to control the border of the button
  • Command, CommandParameter : Values for the command to be executed when clicked
  • Font : Attributes of the font
  • IsEnabled, IsFocused, IsVisible : Values to drive button’s behaviors
  • Text : Text on the button
  • TextColor : Color of text on the button 

ActivityIndicator. An indicator that shows there is an action processing and the user needs to wait for it to complete

  • Color : Color of the indicator
  • IsEnabled, IsFocused, IsRunning IsVisible : Values to drive activity indicator’s behaviors

ProgressBar. Used to display how far along a process is

  • IsEnabled, IsFocused, IsVisible : Values to drive the control’s behaviors
  • Progress : Value to show completion…I think this is a value from 0.0 to 1.0

TimePicker. Used to select a time value

DatePicker. Similar to TimePicker, but used to select a date

  • Date : The date value of the control
  • Format : Format to display, using standard C# formats

Switch. Used to input whether a boolean property is true or false

  • IsToggled, IsEnabled, IsVisible, IsFocused : Drive control’s behaviors

SwitchCell. Displays a label and a switch

  • Text : The text of the label
  • On : A boolean value of whether the switch is toggled
  • Height : The height of the control

ViewCell. A basic layout control that displays an item in a data template. Does not have the basic properties.

  • Height : Height of cell to display

StackLayout. Similar to a StackPanel in Windows XAML, used to display items in a stack. Has the common properties as well

  • Padding : The area around the layout, displayed as an integer or series of values “left, top, right, bottom”… i.e. “20,0,0,0” means left margin of 20, zero on other sides
  • Spacing : The area between items
  • Orientation : Horizontal vs Vertical

Grid. Layout in Columns and Rows, using various spacing options, such as fixed, Auto and Star – *

  • RowDefinitions, ColumnDefinitions : Same as Windows XAML
  • RowSpacing, ColumnSpacing : distance between columns and rows, defaults to 6 px

ListView. Container for collections of items…

  • ItemsSource : The data collection used to populate the list
  • SelectedItem : If an item is selected in the list
  • IsEnabled, IsGroupingEnabled, IsVisible : Drives list’s behaviors
  • RowHeight : Height of item’s row
  • HasUnevenRows : A flag that indicates row height varies
  • Triggers : connects an item to a behavior
  • ItemTemplate : Binding template for item’s display
  • GroupHeaderTemplate : Binding template for list’s header

 

Happy Coding!

image

(originally posted on www.benkotips.com follow me on http://twitter.com/mbenko)

I'm creating a Xamarin.Forms project, using XAML for markup that includes an authentication page when the app starts. I am using a TabbedPage (also tried CarouselPage) as the container of my main UI and plan to have several pages displayed. The first page (myDashboard) checks to see if the user has authenticated and if not I want to display a modal login page. When they return I would like to load data based on their user id.

What's happening is that the Dashboard page loads and is immediately overlaid by the myLogin page, but then all the DisplayAlerts show in succession before I do anything. When I call PopModalAsync() on the login page the OnAppearing method doesn't continue, which indicates to me that the await call had no effect in interrupting the process flow, as if it's already completed the calls after the PushModalAsync() call. (I plan to remove the DisplayAlert calls when it's working as expected.)

My code looks like this...in the App class:


    var mainPage = new TabbedPage() { Children = { new myDashboard() } };
    return mainPage;
    

 

In the myDashboard() class:

    protected async override void OnAppearing()
   {
       base.OnAppearing();
       try
       {

           await DisplayAlert("Alert", "OnAppearing Start", "ok", null);

           if (App.context.IsLoggedIn == false)
           {
               await Navigation.PushModalAsync(new myLogin());

               if (App.context.IsLoggedIn == true)
               {
                   // await LoadData();
                   PageLabel.Text = "Hello " + App.context.UserInfo;
               }
           }

           await DisplayAlert("Alert", "OnAppearing LoggedIn", "ok", null);

           await LoadData();
           await DisplayAlert("Alert", "OnAppearing Complete", "ok", null);
       }
       catch (Exception ex)
       {
           var err = ex.Message;
       }
   }
   

What am I missing?

It appears that because this code is in the OnAppearing() event which is called during a Pop or a Push that the behavior isn’t what is expected. I found an approach in the Xamarin Forums which wires up an event to the login page to send an event and then subscribe to it from the caller (see how-to-navigate-between-contentpages). I removed the code in the OnAppearing event, reserving it for handling core initialization and if the user is logged in I’ll load the data. To implement this approach subscribe to the event in the constructor of your main page…

 

    public myDashboard()
    {
        InitializeComponent();
        MessagingCenter.Subscribe<myLogin>(this, "LoginComplete",(sender) => LoadData());
    }
    

Then in the login page add code to send the message right after calling PopModalAsync() to close the window.

 

    
    public async void OnButtonClicked(object sender, EventArgs e)
    {
        var rc = await DisplayAlert("Alert!", "Logged in as " + myPhone.Text, "Ok", "Cancel");
        if (rc == true)
        {
            App.context.IsLoggedIn = true;
            await Navigation.PopModalAsync();
            MessagingCenter.Send<myLogin>(this, "LoginComplete");
        }
    }
    

It works, but is there a better way?

Short Answer – Don’t use special characters in a Mobile Service’s project name when you create it, the local SQL won’t be able to open the database and you may spend a lot of time figuring out why chasing down false leads…

The Long Answer…

In my last role at Microsoft as an Azure Evangelist I posted a series of cloud tips, which were intended to be quick tips for using the latest tools & services. This one is the next in that series, and focuses around some esoteric gotcha’s that come up when you’re following a convention for organizing your solution in Visual Studio. As you probably are aware you can have multiple projects in a solution, and one approach for keeping them organized is to follow a naming standard that uses a dot-syntax to keep related related things in their right spot.

For example if my project is a solution to a to-do list, I might create the solution called “TestData”, and within that solution have a project for the web called “TestData.web” and a shared project called “TestData.shared”. Following this convention it makes sense if I want to add a data service project I might call it “TestData.svc”, right? When I try this out and build it, I was finding an error that took longer to expose than I had planned, and that’s the focus of this post.

image

I started with this solution and added some custom classes to the data tables to work with my TestData and found that I was getting  errors. The Mobile Services project type includes a testing page that allows me to try out the service and test the calls to my data, which is great. But I found that I was getting an error when I was running the project without adding or changing anything…Isn’t the stuff supposed to work “out of the box”? Instead I get the error - “The database name 'TR_TestData_svc]_TodoItems_InsertUpdateDelete' is invalid. Database names must be of the form [<schema_name>.]<object_name>”. What does this mean???

image

Don’t do this…

It looks like something’s not right with EF, so I tried updating my NuGet’s to make sure I have the latest packages…Right click the project explorer and go to the NuGet page and try update packages…this is the wrong thing to do because the template was created using specific versions of specific packages, and while some can be updated others shouldn’t.

This time I get an error that the JWTSecurityTokenHandler is broken. After some digging I found a StackOverflow post that answers this.  In particular I find that EF is unhappy with the latest MobileServices entity versions so in the NuGet Package Manager I need to uninstall the WindowsAzure.MobileServices.Backend packages and install the specific version 1.0.342.

Do this…Don’t name your Mobile Service project with special characters in the name

The problem isn’t with EF or out of date packages, it has to do with the local database name not being recognizable with the dot-syntax naming convention (another StackOverflow post). In the web config you can fix it by removing the period in the names, or you can do what I did which is just recreate the project without the dot name and test to confirm it’s working, and then rename the services project in the solution.

image

And it works! Time to go and write some code.

Originally posted on: http://geekswithblogs.net/benko/archive/2014/12/03/how-to-detect-an-ios-device-when-working-with-xamarin.aspx

Xamarin + WAMS = Happiness (well, most of the time)

imageFirst some background…I spent the last couple months trying to figure out the best approach for cross-platform development stuff. After some research and working thru some POC’s with Apache Cordova, Native and Xamarin we decided to go down the path of Xamarin as the tool of choice. We did this for a few reasons, including that we can use C# for the code, that with Xamarin Forms it supports XAML as our markup which has a native backend for handling responsive design, and because we would like to have one set of code running across the different device platforms, and we can go deep on a platform to light up features as needed. For learning it there’s a nice set of xamples you can start from in GitHub that show working demo apps.

Secondly we’re using Azure Mobile Services (WAMS) with the .NET implementation so we can customize the authentication process to suit our needs (more on that in another post). The Node.js implementation is fast, but it has its limitations when we have multiple environments, need to work with specific 3rd party libraries, and we wanted to be able to debug completely offline. The new generation of WAMS with .NET does this by providing a WebAPI style implementation that lets me run the service locally and have complete control. All is good.

To build for iOS the configuration requires not just Xamarin but also a mac build machine. I went to Best Buy and found a reasonably inexpensive mini device, and with some cable magic I can connect it to a spare monitor and set it up. It takes a bit of configuration and creation of accounts with Apple to get it working as a dev machine, including registering with the developer program and getting a certificate to build with. The documentation on Xamarin’s site is pretty good on this.

All is good, and I’m able to build out the examples and deploy to my Windows Phone and Android devices, but when I try to detect an iPad (attached to my mac-mini build machine) it says no devices are attached.  When I click the drop down list of debug devices it shows the iOS simulator options. I don’t see the iOS device I have attached to my build machine! What to do?

image

Searching the issue finds some ideas, but after an hour or so of restarting Visual Studio, the mac, and reconnecting the build host and then restarting Visual Studio I find that sometimes it sees my device but then quickly switches to the simulator as the only options to test on. I prefer to run on real devices (a result of attempting to use the Android simulators and waiting in vain for them to start), and also I don’t have the monitor hooked up to the mac except when I turn it on to log in. I found this Stack Overflow post which further down had a nugget of info that solved my problem.

In a multi-project solution in Visual Studio the place to look is the configuration manager. Right click on the solution and open it up. Change the iOS project from iPhoneSimulator to iPhone and Bang! your issue is solved.

image 

Now when I look at my targets for the iOS project it shows my device.

image

All is good. Happy Coding!

I want to help people be aware of some of the scams going on. Lately I’ve been getting a number of emails that are needing some attention.The latest phishing scam example is fairly clever, disguising itself as a voicemail received by outlook. It includes text with a bogus phone number and a link to a zip file they want you to open that includes the exploit. Notice that the from email says Microsoft Outlook Voicemail which might be a real source of stuff for you, but the actual email is from the domain “documents233.com”!

 

image

 

Taking a closer look at where this comes from you can run a Whois to see the registration information on the domain…which shows the domain is owned by some company in China! Should you open this up? Only if you want to install their virus on your machine, because the attached zip is an executable that wants to install stuff when you run it.

 

image

Just saying…always be careful what you click!

-mike

ExtremeHackerThis week we're doing a session called "Avoiding Hacker Trix" which goes thru some of the top web exploits that you should be aware of. In this webcast we will cover a variety of things including what we call the secure development process, cross site scripting attack, one click attack, SQL Injection and more. There are a bunch of links we cover, but rather than having you copy these down I'm providing them here...

Links from the slide deck:

Preview for DevelopersWoot! I’ve got it, the new preview release of Windows Phone 8.1. Since the announcements at Build where they introduced the next generation of apps for Windows and Windows Phone I’ve been working to get the tools and start the learning process to be ready to build for the new devices. If you’re looking to do the same there are a few steps to follow, but it’s not that difficult, although it takes some time and a couple steps to complete.

Here’s what you need to do…

  1. Get a Windows 8 phone. This can be any wp8 device, I’ve been using Nokia devices lately. The 820 is nice and I like the size and format.
  2. Register as a developer on http://create.msdn.com – this is the developer portal where you can get started building for Windows. There is a registration cost of $19 if you’re not in the program. Another option is to register with App Studio – where you can literally create an app in minutes and have it running on your device.
  3. Download the phone registration tool to unlock your device for development. This is included with the tools for Windows Phone download.
  4. Unlock the phone
    Developer_Registration_Tool
  5. Install the preview app on your phone
  6. Check for updates and install them on your phone…it will walk you thru the process

The preview app allows your phone to download the bits and install them. You may need to check for updates (in the phone settings) a couple times, but when you do it will do the necessary work. I found that it took me more than an hour to complete (make sure your phone is charged before you start) and I had to run the check for updates 3 times to get all the prerequisites to get to the 8.1 install, but persistence paid off.  Now it’s time to start building some universal apps.

Ok, Cortana, what next?

Mike

Did you know that visitors are always welcome at TechMasters.    In the Edina location some members arrive around 7:30 AM and the meeting starts promptly at 7:40 AM.  Visitors are still welcome to come after the meeting has started.  We break around 8:15 and finish at 9:00, so we have a chance to welcome you even if you arrive after the meeting starts.     Please stop over, sign our guest book and fellow members will be happy to talk with you about TechMasters.  The full schedule for the Edina location can be found here.

 


The post Did you know… appeared first on TechMasters - Twin Cities.

imageYesterday in Dallas we had Scott Guthrie (@ScottGu) and the Azure team put on a great event at the Irving Convention Center to show off what’s new in the Microsoft Cloud story and to dive into getting started with the tools and services that make it work. Chris Koenig did a great job of coordinating the event and Adam Hoffman, Clint Edmonson and Brian Prince all pitched in with sessions about Virtual Machines, Web Sites and how to work with the services.

imageMy talk was on Building Connected Windows 8 Metro applications with Windows Azure, and we showed how to use the Camera UI to upload images to Blob Storage, Geolocation to add a point of interest to a SQL Azure database and then add a pin to a Bing Map, and finally add Notification Services to update the Live Tile. It was a lot of code and I promised to share it here, so if you’re looking for the link to download it is http://aka.ms/dfwWin8Az.

Here are some notes to be able to build out & deploy locally and then migrate the services to Azure…

image- This project is designed to run locally against the Azure Storage Emulator and SQL Express. It can easily be modified to run as a cloud service, see steps below.
- Do a CTRL+SHIFT+F to search for "TODO" to find all the places where you need to personalize settings
- I've included the script MsdnDB.sql which should be run against a local instance of SQL server, or against a cloud instance.
- You should download the Bing Map VSIX installer to add functionality for Metro. Download the latest from Visual Studio Gallery here
    http://visualstudiogallery.msdn.microsoft.com/0c341dfb-4584-4738-949c-daf55b82df58

- I used several packages to enable notifications. These included
    For MyApp  --> PM> Install-Package Windows8.Notifications

    For MySite --> PM> Install-Package WindowsAzure.Notifications

                   PM> Install-Package wnsrecipe

- To deploy to the Cloud
  1. Create an Azure Web Site from the Management console, then download the publish settings from the web site dashbaord
  2. Create a storage account and update the web.config of MySite with appropriate storage credentials
  3. Create a SQL Azure database
  4. Run the create script MsdnDB.SQL (included) against database
  5. Update credentials in web.config of MySite
  6. Change MyApp MainPage.xaml.cs URI's to point to your site instead of localhost:19480
  7. Run the NuGet Packages from Package Manager console
  8. Register your app for notifications on https://manage.dev.live.com/Build
     - update the Package Name reference in Package.appxmanifest
     - Add the SID and Client secret to the SendNotification method in LocationController.cs


Enjoy!
-mike

Digg This

It’s been a busy week by anyone’s estimation. We announced new capabilities in Windows Azure, a new Windows 8 Tablet called Surface, and now Windows Phone comes to the front.   Some great stuff has been announced around the future of Windows Phone yesterday. Here’s a summary of the core 8 features which include:image

Multi-core processor support: As reviewers have noted, Windows Phone runs buttery smooth on phones with a single processor. But piggybacking on the Windows core provides support for multiple cores—so we’re ready for whatever hardware makers dream up.

Bigger, sharper screens: Windows Phone 8 supports two new screen resolutions—1280x768 and 1280x720, opening the door to amazing new handsets with high-definition 720p displays.

More flexible storage: Windows Phone 8 supports removable MicroSD cards, so you can stuff your phone with extra photos, music, and whatever else is important to you, and then easily move it all onto your PC.

NFC wireless sharing: If you haven’t heard the term “NFC” yet, I’m betting you soon will. This emerging wireless technology lets phones share things over short distances. In Windows Phone 8, it helps make sharing photos, Office docs, and contact info easier—just tap your phone another NFC-equipped device. How cool is that?

Internet Explorer 10: The next version of Windows Phone comes with the same web browsing engine that’s headed for Window 8 PCs and tablets. IE10 is faster and more secure, with advanced anti-phishing features like SmartScreen Filter to block dangerous websites and malware.

Wallet: Windows Phone 8’s new digital Wallet feature does two great things. It can keep debit and credit cards, coupons, boarding passes, and other important info right at your fingertips. And when paired with a secure SIM from your carrier, you can also pay for things with a tap of your phone at compatible checkout counters.

Better maps and directions: Windows Phone 8 builds in Nokia mapping as part of the platform. Our partnership will provide more detailed maps and turn-by-turn directions in many countries, plus the ability to store maps offline on your phone so you can work with maps without a data connection.

Cooler apps and games: Basing Windows Phone 8 on the Windows core will unleash a new wave of amazing apps and especially games, for reasons

For a more detailed write up check out the blog post here:

http://windowsteamblog.com/windows_phone/b/windowsphone/

You can also check out a recording of the summit here:

http://channel9.msdn.com/Events/Windows-Phone/Summit

Great stuff coming, stay tuned!

-mike

Digg This
Load more...