Tuesday, August 27, 2019

Loading an image into an ImageButton from an EmbeddedResource

Sad, but this took me awhile to figure out.  A lot of the examples on the web are incorrect so it took quite a bit of thrashing to figure this simple thing out.

The way to load an image into an ImageButton from an EmbeddedResource is to of course add an image to your project and mark it as EmbeddedResource. 

The next step is to determine the “path” to this resource.  If the project name is “Project” and the folder you added your image to is named “Folder” and the image is named “Image.png” then the “path” to this image is "Project.Folder.Image.png”

Then it is a simple process to use the static class ImageSource, like this:

ImageSource.FromResource("Project.Folder.Image.png")

Sunday, August 25, 2019

Back in the (programming) saddle again!

I never thought it could happen to me.  I had publicly said, many times, that it just could never happen to me because it was such an integral part of my life, but it did.

I burnt out on programming.

I was stretched just too thin.  My personal life was falling apart from dealing with my wife’s two year losing battle with cancer.  I worked for, what some people would call, one of the best companies in the world: CSG International.  They allowed me to work first from home and then later from the hospital as I cared for my wife.  They bent over backwards to help me through this most painful of times.  But, in the end I realized that I just could not write code anymore.  I was totally burnt out.  So, I did the only honorable think I could do .. I resigned.

And, in my personal life, I was completely drained. After my wife passed, I just needed to escape.  so I did.

To the Philippines.  I have now remarried to a beautiful Filipina and I now have a … DAUGHTER!

When I moved, my sister said that I would be back at the keyboard pounding out code in no time.  Knowing how much programming meant to me, she predicted it would only take two months.

Eighteen months later …

I am finally getting the itch to program again and I have started to learn how to write mobile apps using the Xamarin platform.  I have already hit some snags that were not the easiest to unravel so I figured I would share my journey with the world.

Programming, I missed you!  Welcome back!



Tuesday, August 30, 2016

Changing the ZIndex of a XAML Element using a Storyboard


One of my current projects has two XAML elements moving in 3D and as the  second element eclipsed the first element the ZIndex had to be changed so the second element would now appear in front of the first. 

Lots of searching later (and quite a few articles saying that it was not possible) I came up with a XAML based Storyboard that worked, but since I needed to build the Storyboard programmatically, I needed to convert it to C# code.

This is what I came up with:

Code Snippet – CreateZIndexStoryboard
  1. private Storyboard CreateZIndexStoryboard(FrameworkElement fromElement, int newZIndex)
  2. {
  3.     var myZIndexStoryboard = new Storyboard();
  4.     var myZIndexAnimation = new ObjectAnimationUsingKeyFrames();       
  5.     var myZIndexKeyFrame = new DiscreteObjectKeyFrame
  6.     {
  7.         Value = newZIndex,
  8.         KeyTime = TimeSpan.FromMilliseconds(AnimationLength/2)
  9.     };
  10.  
  11.     myZIndexAnimation.KeyFrames.Add(myZIndexKeyFrame);
  12.  
  13.     myZIndexStoryboard.Children.Add(myZIndexAnimation);
  14.  
  15.     Storyboard.SetTarget(myZIndexAnimation, fromElement);
  16.     Storyboard.SetTargetProperty(myZIndexAnimation, "(Canvas.ZIndex)");
  17.  
  18.     return myZIndexStoryboard;
  19. }

One of the main points of difference between Silverlight and Windows Universal XAML is that setting the target property on the storyboard, ie. Storyboard.SetTargetProperty is that in silverlight you would set the path to the property by creating a new PropertyPath object.  With Windows Universal XAML you using a binding to a property using a string with binding syntax.