I spoke at the 2017 Code Impact in Jacksonville Florida on Aug 26. The sample code and power point for my talk on Use .Net Standard with Xamarin forms can be found on my Git Hub repo.
https://github.com/vb2ae/CodeImpactNetStandard
Sunday, August 27, 2017
Wednesday, March 8, 2017
VS 2017 setup the product definitions failed to load
I tried to upgrade my Visual Studio 2017 RC to the release version and got an error product definitions failed to load
The way I got the installer to work was to delete the folder %LocalAppData%\Microsoft\VisualStudio\Packages\
After that running the installer I was able to update my install to the released version
The way I got the installer to work was to delete the folder %LocalAppData%\Microsoft\VisualStudio\Packages\
After that running the installer I was able to update my install to the released version
Sunday, March 5, 2017
Cloning an Object in an PCL
Here is an example on how to clone an object in a portable class library
I am using Json.net to help. Add the Json.Net nuget package to any project in the solution that uses the PCL
public T CloneObject<T>(T toBeCloned)
{
T clone = default(T);
string serialized = JsonConvert.SerializeObject(toBeCloned);
clone = JsonConvert.DeserializeObject<T>(serialized);
return clone;
}
I am using Json.net to help. Add the Json.Net nuget package to any project in the solution that uses the PCL
Then you an serialize the object into Json and then deserialize it right away to create a clone of a object
public T CloneObject<T>(T toBeCloned)
{
T clone = default(T);
string serialized = JsonConvert.SerializeObject(toBeCloned);
clone = JsonConvert.DeserializeObject<T>(serialized);
return clone;
}
Sunday, February 26, 2017
Visual Studio 2017 live unit tests
I was experimenting today with VS 2017 live unit testing. I really like them a lot. I wish they were available in all editions of VS 2017 not just enterprise.
I started with a simple console app. Which adds 2 numbers.
public class Program
{
static void Main(string[] args)
{
Console.Write("1 + 1 = ");
Console.WriteLine(Add2Numbers(1,1).ToString());
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
public static int Add2Numbers(int x,int y)
{
return x * y;
}
}
Then I added a Unit Test project. I added a project reference to my ConsoleApp
Here is the tests I added.
Namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
int x = 1;
int y = 1;
int expected = 2;
Assert.AreEqual(expected, ConsoleApp1.Program.Add2Numbers(x, y));
}
}
}
Then I build the project and ran the test. As you can see the test failed.
Lets turn on the Live Unit Tests in Visual Studio's Options. There is a section for it.
public static int Add2Numbers(int x,int y)
{
return x + y;
}
I started with a simple console app. Which adds 2 numbers.
public class Program
{
static void Main(string[] args)
{
Console.Write("1 + 1 = ");
Console.WriteLine(Add2Numbers(1,1).ToString());
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
public static int Add2Numbers(int x,int y)
{
return x * y;
}
}
Then I added a Unit Test project. I added a project reference to my ConsoleApp
Here is the tests I added.
Namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
int x = 1;
int y = 1;
int expected = 2;
Assert.AreEqual(expected, ConsoleApp1.Program.Add2Numbers(x, y));
}
}
}
Then I build the project and ran the test. As you can see the test failed.
Lets turn on the Live Unit Tests in Visual Studio's Options. There is a section for it.
Right click on the solution in the solution explorer and select Live Tests and select include.
Here is what you will see.
Now if we update the code. We will see it goes to passing
public static int Add2Numbers(int x,int y)
{
return x + y;
}
Very useful feature.
Saturday, December 31, 2016
Xamarin Android Multiline label not working properly
I was having an issue with getting a Label to multiline in an Xamarin forms ListView in an android app.
My XAML was this
My XAML was this
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="XamarinDev.BlogPage"> <ListView ItemsSource="{Binding BlogPosts}" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Padding="15,0" HorizontalOptions="Fill" VerticalOptions="StartAndExpand" > <Label Text="{Binding Title}" FontAttributes="Bold" LineBreakMode="WordWrap"/> <Label Text="{Binding Description}" LineBreakMode="WordWrap"></Label> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
And it looked like this
After I added HasUnevenRows="True"
to the listview I got much better results
<ListView ItemsSource="{Binding BlogPosts}" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Padding="15,0" HorizontalOptions="Fill" VerticalOptions="StartAndExpand" > <Label Text="{Binding Title}" FontAttributes="Bold" LineBreakMode="WordWrap"/> <Label Text="{Binding Description}" LineBreakMode="WordWrap"></Label> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
Xamarin forms android emulator app not updating when debugging
I find that sometime when I am debugging a Xamarin Forms apps on a windows 10 machine the android apps do not show the latest updates in the emulator. Typically when debugging on a windows 10 machine I do most of my debugging in the UWP app but when I switch to the hyper-V android emulator the app does not always show the latest changes. To solve this I stop debugging the android version, go to the emulator and uninstall the app. The next time you be debug you will see the latest version
Saturday, December 10, 2016
Fixing your Hyper-V emulators
If you are having problems getting your hyper-v emulators to run here are the steps I recommend to fix them
First and this usually fixes the issue. Open the Hyper-V manager and delete all the virtual switches you will find them under the virtual switch manager
Try running the Hyper-V emulators again the switches will be recreated. In the rare chance they still do not work go ahead and delete the virtual switches again.
First and this usually fixes the issue. Open the Hyper-V manager and delete all the virtual switches you will find them under the virtual switch manager
Try running the Hyper-V emulators again the switches will be recreated. In the rare chance they still do not work go ahead and delete the virtual switches again.
Now delete the virtual machines for the emulators. Finally open the Device Manager and delete any hyper-v network adapters you might have
Rerun the emulators and they should work everything you deleted will be recreated.
Subscribe to:
Posts (Atom)
-
If you are having problems getting your hyper-v emulators to run here are the steps I recommend to fix them First and this usually fixes t...
-
If you have the Anniversary update windows 10 pro or greater you can enable long file names in group policy. Search for group policy edit...
-
I have used the NoSql database Lex.DB in some of my mobile apps in the past. The DB was actually very handy and it worked on Xamarin.iOS, X...