tag:blogger.com,1999:blog-187246572024-03-05T00:29:00.559-08:00Andrei's blogsharing coding bitsAndrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.comBlogger121125tag:blogger.com,1999:blog-18724657.post-59279366670608737482019-01-10T09:44:00.002-08:002020-05-08T09:10:18.011-07:00Xamarin Forms: Lazy load tabs in TabbedPage<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-30938901345408789662018-10-17T12:30:00.003-07:002018-10-30T03:44:22.587-07:00Too much fun with Xamarin Forms <div class="separator" style="clear: both; text-align: left;">
I had a blast playing with Xamarin Forms and SVGs which end up with the following which works on iOS, Android and Windows UWP, checkout the videos for Android and iOS apps:</div>
<br />
<div class="separator" style="clear: both;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dzX9y2q3NArEFcT93t71_MyQXd3WWQQF2nEGCyljNyJJ6AALcJL7cwp1JE7oWsKCSbXDsA9bb1Y08s' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<div class="separator" style="clear: both;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/pLn-LWBfkz0/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/pLn-LWBfkz0?feature=player_embedded" style="clear: left; float: left;" width="320"></iframe></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Credit for original design idea goes to Mikael Ainalem:</div>
<div class="" style="clear: both; text-align: left;">
<a href="https://twitter.com/mikaelainalem/status/963076814183772160">https://twitter.com/mikaelainalem/status/963076814183772160</a></div>
<div class="" style="clear: both; text-align: left;">
<br />
The SVG is created dynamically, based on the position of the text-boxes and the button, so it will work on any number of text-boxes and buttons. The actual SVG for the login screen in the videos, looks like this:</div>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxWOopI9J_N3Q2gNEu3orqwatv-QWZD90BviR7rrxMc-S8M-CNEaENUeWdwHLjXUSfs2_4O4zmXJyZkbGWHNZJT63o-yarBxe9rWqKlcjMuDwxhPHbVGJcatgpKJ8d_DQTZF2-1g/s1600/snip_20181018083518.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" data-original-height="439" data-original-width="456" height="308" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxWOopI9J_N3Q2gNEu3orqwatv-QWZD90BviR7rrxMc-S8M-CNEaENUeWdwHLjXUSfs2_4O4zmXJyZkbGWHNZJT63o-yarBxe9rWqKlcjMuDwxhPHbVGJcatgpKJ8d_DQTZF2-1g/s320/snip_20181018083518.png" width="320" /></a><br />
<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-88215722106107490802015-09-04T04:02:00.003-07:002015-10-30T09:31:40.886-07:00Debugging HTML5 running in iOS from Windows with Chrome dev tools!<br />
In order to debug HTML5 running in Safari on iOS, I used to connect the iOS device to my Mac, open Safari, go to Developer menu(needs to be activated from Safari Preferences) and open the page.<br />
You can find detailed steps how to do this on internet.<br />
<br />
I tried to remote debug HTML5 with other tools (Telerik has one), but the best way is with an utility called <a href="https://github.com/google/ios-webkit-debug-proxy">ios-webkit-debug-proxy</a> which uses Chrome dev tools!<br />
<br />
You can find it here <a href="https://github.com/google/ios-webkit-debug-proxy">https://github.com/google/ios-webkit-debug-proxy</a> and its Windows port: <a href="https://github.com/artygus/ios-webkit-debug-proxy-win32">https://github.com/artygus/ios-webkit-debug-proxy-win32</a><br />
<br />
It allows you inspect the WebKit (either the Safari or UIWebViews) running on the iOS device from your Windows machine with Chrome dev tools.<br />
This utility connects to the WebKit for inspection.<br />
<br />
Steps (most of these are written in <a href="https://github.com/google/ios-webkit-debug-proxy">https://github.com/google/ios-webkit-debug-proxy</a>):<br />
<ol>
<li>Go to <a href="https://github.com/artygus/ios-webkit-debug-proxy-win32">https://github.com/artygus/ios-webkit-debug-proxy-win32</a></li>
<li>You can either get the compiled version or build from the source. I chose to built it from source just for the kicks.</li>
<li>Run the ios-webkit-debug-proxy.exe</li>
<li>In Chrome, go to <a href="http://localhost:9222/">http://localhost:9222/</a> to see web-browser tabs open in Safari or the WebViews on the iOS device. Click on a tab.</li>
<li>A new window should open with Dev tools. Note the silver icon, click on it and choose to 'Load unsafe scripts':</li>
</ol>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC8H_YQBFyyl7toWJzAkTFt3mk32_mf8cgpsJKLXO-dSejhVN4bfvVyQHmhwHIK3zXQgH-rbGk77_FfeEJH_N5y6GnsjrLLHmS_BQW2ZjvgorN7C1yM4t1yFPCABGgUMEoWtwGLw/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiC8H_YQBFyyl7toWJzAkTFt3mk32_mf8cgpsJKLXO-dSejhVN4bfvVyQHmhwHIK3zXQgH-rbGk77_FfeEJH_N5y6GnsjrLLHmS_BQW2ZjvgorN7C1yM4t1yFPCABGgUMEoWtwGLw/s1600/Capture.PNG" /></a></div>
<br />
<br />
Some things to keep in mind:<br />
<br />
- note that a web server is being used. when inspecting a tab, the link is<br />
https://chrome-devtools-frontend.appspot.com/static/27.0.1453.93/devtools.html?host=localhost:9222&page=1<br />
not sure if this might be a security issue for what you're debugging.<br />
<br />
- in the inspector window, clicking on elements in the Elements tab doesn't do anything; you can use arrow keys to navigate up and down in the DOM tree<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<br />
<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-71305177279050018842015-06-22T05:56:00.001-07:002018-10-29T07:01:00.491-07:00GridSplitter control for Xamarin FormsI created a GridSplitter control for Xamarin Forms, for iOS and Android.<br />
<br />
You can find the full description of how it works and how to include it in your app:<br />
<a href="https://github.com/andreinitescu/GridSplitterApp" title="https://github.com/andreinitescu/GridSplitterApp">https://github.com/andreinitescu/GridSplitterApp</a><br />
<br />
Some screenshots with sample layouts included in the sample app:<br />
<br />
<a href="http:shttps://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZkl7-VKua7A-_FV540JCD6K161DLwDzQgbcM4ubOK3oAu009v1v7urczBaEosr9BkpUimt48DqBHGBBh7s9JrHH6Th_PGPYpjCFXQ82dBO6zo1Eqdnu-R-TuE_mJ3GjYRUm23TA/s1600-h/mGkd879Oqv%25255B3%25255D.gif"><img alt="mGkd879Oqv" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8qtBxNQUmTPvreLf6ED8oq5XYFC3atMbtuAITIg_NZ0DoiJeQOTIwqrxdbaPCJGopufpWW5hYZDRi6FneGf4JJa0RQHcc2zyd91EMYjQDoB_ybC7a_lLY6vXit3NXyylP3W9kjA/?imgmax=800" height="483" style="display: inline;" title="mGkd879Oqv" width="787" /></a><br />
<br />
and a Grid with both horizontal and vertical splitters:<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE2BIFmudzw3ktTez1x3cBhkklGwhNsquA6vHvXR42WXHzjy2QLfy-KYmNvnnh3NfDsvzUeyDBPzKlMpCyYkwLvyswmUtYE0cqiaiukZDzO8DZw0L_cI0d-eALh8EDfq-NkD10Hg/s1600-h/DnaXEi1wzw%25255B3%25255D.gif"><img alt="DnaXEi1wzw" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFvG1hCu67wH_O43jHlkql93NFulKr16drWyvfa9OP0nqrrmw-Bvu2ZRVh7SVDnxjihJX2tG4-_hShnlXONWWnv9ojxuHUYyjGYnnSJRYdnL0JT0Z6fPDMOtoTz4CrbfEB7MqAA/?imgmax=800" height="473" style="display: inline;" title="DnaXEi1wzw" width="771" /></a><br />
<br />
The sample app also shows a technique to create reusable custom controls which you can style easily just with XAML, very similar to how it works on Windows.Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-21593678162600738312015-06-17T03:43:00.001-07:002018-10-29T06:38:29.866-07:00Easiest way to know which w3wp.exe PID corresponds to which application pool I keep forgetting this.<br />
Open Task Manager and have it show the Command Line column<br />
You can see for the w3p.exe processes the name of the app pool in the command line parameters<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVrP3GAM12ABkYKM_0CQ8n6GmMPf7z0QTq3b-qI9nCmPPmKgIS_jACLrbHxRFflXLkVLXSUSNKH6Ih8DmeXOLfmeSZrwnfa_stgMGkZXOjk0UplglSWP_zCXPLRxnloPIq9TS1pQ/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="270" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVrP3GAM12ABkYKM_0CQ8n6GmMPf7z0QTq3b-qI9nCmPPmKgIS_jACLrbHxRFflXLkVLXSUSNKH6Ih8DmeXOLfmeSZrwnfa_stgMGkZXOjk0UplglSWP_zCXPLRxnloPIq9TS1pQ/s640/Capture.PNG" width="640" /></a></div>
<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-41781071557141510312015-06-10T13:05:00.001-07:002018-10-29T06:59:49.152-07:00Xamarin Forms: Create a style BasedOn default style defined in app's global resource dictionarySuppose there’s a style defined in app's global resource dictionary (App.xaml):<br />
<br />
<code><Style TargetType="Label"><br /> <Setter Property="TextColor" Value="Red" /><br /></Style></code><br />
And this style defined in a page:<br />
<br />
<code><Style x:Key="MyLabelStyle" TargetType="Label"><br /> <Setter Property="FontSize" Value="14" /><br /></Style></code> <br />
If you want MyLabelStyle to inherit the global style, one way is to use this syntax:<br />
<br />
<code><Style x:Key="MyLabelStyle" TargetType="Label" BasedOn=”{StaticResource Xamarin.Forms.Label}”> </code><br />
<br />
otherwise MyLabelStyle will not have the text color red.<br />
<br />
Note that this won’t work:<br />
<code><Style x:Key="MyLabelStyle" TargetType="Label" BasedOn=”{StaticResource {x:Type Label}}”></code><br />
<span style="font-family: "times new roman";"><br /></span>
<span style="font-family: "times new roman";">I</span><span style="font-family: "times new roman";">nstead of hard coding the Label’s type full name, a nicer way would be to define a custom markup extension which resolves the Label type (something like <a href="https://github.com/andreinitescu/GridSplitterApp/blob/master/GridSplitterApp/GridSplitterApp/Controls/ParentStyleMarkupExtension.cs">this</a>)</span>Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-51272783651051857342015-06-10T00:40:00.003-07:002015-06-10T02:17:14.513-07:00Xamarin Forms style resets There are some default styles which you might want to reset in your Xamarin Forms apps.<br />
For example, some container controls have default padding and spacing for their child views.<br />
<br />
In a more complicated UI, sometimes these default styles can become an issue. Because the UI you build is complex, you can forget about these default values and you wonder why some views are not positioned the way you want.<br />
<br />
I created a small XAML 'resets' snippet, which can be added to the App.xaml:<br />
<a href="https://gist.github.com/andreinitescu/69e8afcad1ed9de69b76">https://gist.github.com/andreinitescu/69e8afcad1ed9de69b76</a>Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-5444756551083824432015-06-10T00:30:00.004-07:002015-06-10T00:34:53.782-07:00Add App.xaml in your Xamarin Forms project<div>
In the current version of Xamarin tools, the default Xamarin Forms project templates in both Visual Studio and Xamarin Studio do not generate App.xaml along with the App class that derives from Application and provides an entry point where you can add initialization code. </div>
<div>
<br />
The support for App.xaml is briefly mentioned in <a href="http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/styles/#Using_Xaml_for_your_App">Xamarin Forms documentation</a> but without giving the exact steps.<br />
These steps are:</div>
<div>
<br /></div>
<div>
1. Right click on the PCL project and choose to add a new file</div>
<div>
2. In Visual Studio, choose the "Forms Xaml Page" item</div>
<div>
In Xamarin Studio, choose the "Forms ContentPage Xaml" item</div>
<div>
3. Write "App" as name</div>
<div>
<br /></div>
<div>
You will get a App.xaml and App.xaml.cs created. You need to do some small modifications in each of these:</div>
<div>
<br /></div>
<div>
1. in App.xaml, replace the XAML with the following:</div>
<div>
<pre style="background-color: white; border-radius: 6px; border: 4px solid rgb(236, 240, 241); box-shadow: none; color: #4e5758; font-family: Consolas, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 0.8em; margin-top: 0.8em; overflow: auto; padding: 1em 1.2em;"><span class="syntax-container syntax-theme-base" style="position: relative;"><code class="syntax highlighted" style="background: transparent; border: 0px; font-family: Consolas, monospace; font-size: inherit; margin: 0px; padding: 0px; position: relative; top: 1px;"><span class="csharp"><span class="operator" style="color: #268bd2;"><</span><span class="type" style="color: #3364ad;">Application</span>
</span><span class="csharp"> xmlns<span class="operator" style="color: #268bd2;">=</span><span class="string" style="color: #f57d00;">"http://xamarin.com/schemas/2014/forms"</span>
</span><span class="csharp"> xmlns:x<span class="operator" style="color: #268bd2;">=</span><span class="string" style="color: #f57d00;">"http://schemas.microsoft.com/winfx/2009/xaml"</span>
</span><span class="csharp"> x:<span class="type" style="color: #3364ad;">Class</span><span class="operator" style="color: #268bd2;">=</span><span class="string" style="color: #f57d00;">"MyApp.App"</span><span class="operator" style="color: #268bd2;">></span>
</span><span class="csharp"> <span class="operator" style="color: #268bd2;"><</span><span class="type" style="color: #3364ad;">Application</span>.<span class="type" style="color: #3364ad;">Resources</span><span class="operator" style="color: #268bd2;">></span>
</span><span class="csharp"> <span class="operator" style="color: #268bd2;"><</span><span class="type" style="color: #3364ad;">ResourceDictionary</span><span class="operator" style="color: #268bd2;">></span>
</span><span class="csharp"> <!-- Here goes your global styles --></span><span class="csharp">
</span><span class="csharp"> <span class="operator" style="color: #268bd2;"><</span><span class="operator" style="color: #268bd2;">/</span><span class="type" style="color: #3364ad;">ResourceDictionary</span><span class="operator" style="color: #268bd2;">></span>
</span><span class="csharp"> <span class="operator" style="color: #268bd2;"><</span><span class="operator" style="color: #268bd2;">/</span><span class="type" style="color: #3364ad;">Application</span>.<span class="type" style="color: #3364ad;">Resources</span><span class="operator" style="color: #268bd2;">></span>
</span><span class="csharp"><span class="operator" style="color: #268bd2;"><</span><span class="operator" style="color: #268bd2;">/</span><span class="type" style="color: #3364ad;">Application</span><span class="operator" style="color: #268bd2;">></span></span></code></span></pre>
</div>
<div>
<br /></div>
<div>
Note the <span style="color: #4e5758; font-family: Consolas, monospace; font-size: inherit; line-height: 1.5;">x:</span><span class="type" style="color: #3364ad; font-family: Consolas, monospace; font-size: inherit; line-height: 1.5;">Class</span><span class="operator" style="color: #268bd2; font-family: Consolas, monospace; font-size: inherit; line-height: 1.5;">=</span><span class="string" style="color: #f57d00; font-family: Consolas, monospace; font-size: inherit; line-height: 1.5;">"MyApp.App" </span>attribute. You should replace MyApp with the name of your Xamarin Forms project.</div>
<div>
<br /></div>
<div>
2. in App.xaml.cs, replace the base class ContentPage with Application</div>
<div>
<pre style="background-color: white; border-radius: 6px; border: 4px solid rgb(236, 240, 241); box-shadow: none; color: #4e5758; font-family: Consolas, monospace; font-size: 14px; line-height: 1.5; margin-bottom: 0.8em; margin-top: 0.8em; overflow: auto; padding: 1em 1.2em;"><span class="syntax-container syntax-theme-base" style="position: relative;"><code class="syntax highlighted" style="background: transparent; border: 0px; font-family: Consolas, monospace; font-size: inherit; margin: 0px; padding: 0px; position: relative; top: 1px;"><span class="csharp"><span class="access" style="color: #009695;">public</span> <span class="keyword" style="color: #009695;">partial</span> <span class="keyword" style="color: #009695;">class</span> <span class="type" style="color: #3364ad;">App</span> : <span class="type" style="color: #3364ad;">Application</span>
</span><span class="csharp">{
</span><span class="csharp"> <span class="access" style="color: #009695;">public</span> <span class="type" style="color: #3364ad;">App</span> ()
</span><span class="csharp"> {
</span><span class="csharp"> <span class="type" style="color: #3364ad;">InitializeComponent</span> ();
</span><span class="csharp"> <span class="type" style="color: #3364ad;">MainPage</span> <span class="operator" style="color: #268bd2;">=</span> <span class="function" style="color: #555753;">YourContentPage</span>(); <span class="comment" style="color: #999988;">// change as required</span>
</span><span class="csharp"> }
</span><span class="csharp">}</span></code></span></pre>
</div>
<div>
<br /></div>
<div>
You might also need to delete the old App.cs, you don't need it anymore.</div>
<div>
<br /></div>
Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-39074532375808115912015-06-08T08:17:00.001-07:002015-06-09T23:03:13.283-07:00IconView control for Xamarin Forms<br />Someone was asking on the <a href="http://forums.xamarin.com/discussion/31584/image-opacity-mask-to-apply-color-to-image-possible-in-xamarin-forms" target="_blank">forum</a> how to draw a colored icon. <br />I created an IconView control which does this: <a href="https://github.com/andreinitescu/IconApp/">https://github.com/andreinitescu/IconApp/</a><br /><br />The control takes a <a href="http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/images/#Local_Images" target="_blank">local image</a> and applies a color on it. This is useful when you want to color images on the fly, without the need to have multiple images for different colors.<br /><br />At this moment the implementation is for Android and iOS. Contributions for Windows support are welcome!<br />
<h2>
Usage</h2>
An example of a Page using the IconView control:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e175b9ae-334c-4b1a-b479-697eafb4ed80" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 229px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"><?</span><span style="color: black;">xml version</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">1.0</span><span style="color: maroon;">"</span><span style="color: black;"> encoding</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">UTF-8</span><span style="color: maroon;">"</span><span style="color: black;">?></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">ContentPage xmlns</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">http://xamarin.com/schemas/2014/forms</span><span style="color: maroon;">"</span><span style="color: black;">
xmlns:x</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">http://schemas.microsoft.com/winfx/2009/xaml</span><span style="color: maroon;">"</span><span style="color: black;">
x:Class</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">IconApp.MyPage</span><span style="color: maroon;">"</span><span style="color: black;">
xmlns:controls</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">clr-namespace:IconApp;assembly=IconApp</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">controls:IconView Source</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">monkey</span><span style="color: maroon;">"</span><span style="color: black;">
Foreground</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Red</span><span style="color: maroon;">"</span><span style="color: black;">
WidthRequest</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">100</span><span style="color: maroon;">"</span><span style="color: black;">
HeightRequest</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">100</span><span style="color: maroon;">"</span><span style="color: black;">
HorizontalOptions</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Center</span><span style="color: maroon;">"</span><span style="color: black;">
VerticalOptions</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Center</span><span style="color: maroon;">"</span><span style="color: black;"> </span><span style="color: black;">/></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">ContentPage</span><span style="color: black;">></span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
This draws the "monkey" image with red color in the center of the screen:<br />
<br />
<img height="456" src="https://github.com/andreinitescu/IconApp/raw/master/s.jpg" width="277" /><br />
<br />
<h2>
Add the control to your project</h2>
<br />
1. Add <a href="https://github.com/andreinitescu/IconApp/blob/master/IconApp/IconApp/IconView.cs">/IconApp/IconApp/IconView.cs</a> to your Xamarin Forms PCL project<br />2. The control uses native renderes. You need to add the renderers to your Android and iOS project respectively: <br /><a href="https://github.com/andreinitescu/IconApp/blob/master/IconApp/IconApp.Droid/Renderers/IconViewRenderer.cs">/IconApp/IconApp.Droid/Renderers/IconViewRenderer.cs</a> <br /><a href="https://github.com/andreinitescu/IconApp/blob/master/IconApp/IconApp.iOS/Renderer/IconViewRenderer.cs">IconApp/IconApp.iOS/Renderer/IconViewRenderer.cs</a><br />
<br />
Note you might need to update some namespaces. <br /> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-83374478477413948412015-05-26T10:53:00.001-07:002015-05-26T10:56:03.862-07:00CallDataMethod trigger in Xamarin Forms<br /><br />Here’s a very simple implementation of a CallDataMethod trigger in Xamarin Forms:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:b9d83876-1922-4ceb-ab29-b87504e3ddfc" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 328px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> CallDataMethod: TriggerAction</span><span style="color: black;"><</span><span style="color: black;">VisualElement</span><span style="color: black;">></span><span style="color: black;">
{
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">string</span><span style="color: black;"> Method { </span><span style="color: blue;">get</span><span style="color: black;">; </span><span style="color: blue;">set</span><span style="color: black;">; }
</span><span style="color: blue;">#region</span><span style="color: black;"> implemented abstract members of TriggerAction</span><span style="color: black;">
</span><span style="color: blue;">protected</span><span style="color: black;"> </span><span style="color: blue;">override</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> Invoke (VisualElement sender)
{
MethodInfo method </span><span style="color: black;">=</span><span style="color: black;"> sender.GetType ().GetRuntimeMethod (Method, </span><span style="color: blue;">new</span><span style="color: black;"> Type[</span><span style="color: purple;">0</span><span style="color: black;">]);
</span><span style="color: blue;">if</span><span style="color: black;"> (method </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) {
ParameterInfo[] parameters </span><span style="color: black;">=</span><span style="color: black;"> method.GetParameters ();
</span><span style="color: blue;">if</span><span style="color: black;"> (parameters.Length </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: purple;">0</span><span style="color: black;">)
method.Invoke (sender, </span><span style="color: blue;">null</span><span style="color: black;">);
}
}
</span><span style="color: blue;">#endregion</span><span style="color: black;">
}</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<br />
For a demo, let’s say we have two text-boxes (Entry control in Xamarin Forms) and you want to enable the second one when the first has ten characters:<br />
<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a16aee90-3b75-4a7b-9e20-56696f4614ff" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 482px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"><?</span><span style="color: black;">xml version</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">1.0</span><span style="color: maroon;">"</span><span style="color: black;"> encoding</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">UTF-8</span><span style="color: maroon;">"</span><span style="color: black;">?></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">ContentPage
xmlns</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">http://xamarin.com/schemas/2014/forms</span><span style="color: maroon;">"</span><span style="color: black;">
xmlns:x</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">http://schemas.microsoft.com/winfx/2009/xaml</span><span style="color: maroon;">"</span><span style="color: black;">
xmlns:controls</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">clr-namespace:Xamore.Controls;assembly=Xamore.Controls</span><span style="color: maroon;">"</span><span style="color: black;">
x:Class</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Xamore.Controls.TestApp.Views.CallDataMethodPage</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">StackLayout</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">Entry x:Name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">FirstEntry</span><span style="color: maroon;">"</span><span style="color: black;">
WidthRequest</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">100</span><span style="color: maroon;">"</span><span style="color: black;"> </span><span style="color: black;">/></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">Entry IsEnabled</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">false</span><span style="color: maroon;">"</span><span style="color: black;">
WidthRequest</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">100</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">Entry.Triggers</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">DataTrigger TargetType</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Entry</span><span style="color: maroon;">"</span><span style="color: black;">
Binding</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">{Binding Source={x:Reference FirstEntry}, Path=Text.Length}</span><span style="color: maroon;">"</span><span style="color: black;">
Value</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">10</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">Setter Property</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">IsEnabled</span><span style="color: maroon;">"</span><span style="color: black;">
Value</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">True</span><span style="color: maroon;">"</span><span style="color: black;"> </span><span style="color: black;">/></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">Trigger.EnterActions</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">controls:CallDataMethod Method</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Focus</span><span style="color: maroon;">"</span><span style="color: black;"> </span><span style="color: black;">/></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">Trigger.EnterActions</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">DataTrigger</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">Entry.Triggers</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">Entry</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">StackLayout</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">ContentPage</span><span style="color: black;">></span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-90301217565047215332015-05-20T12:22:00.001-07:002015-06-18T02:53:02.976-07:00Manually install Xamarin Studio addins Just copy the .dll file to (note the Xamarin Studio version, it might be different today):<br />
<br />
on <b>Windows</b>:<br />
<b>%LocalAppData%\XamarinStudio-5.0\LocalInstall\Addins</b><br />
<br />
on <b>Mac</b>:<br />
<b>/Users/[YourUser]/Library/Application Support/XamarinStudio-5.0/LocalInstall/Addins</b><br />
<br />
Source:<br />
<a href="http://forums.xamarin.com/discussion/comment/6356/#Comment_6356">http://forums.xamarin.com/discussion/comment/6356/#Comment_6356</a><br />
<br />
<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-82404635620401308532015-05-18T04:32:00.001-07:002015-06-03T10:49:59.788-07:00Add ImageFailed and ImageOpened to the Xamarin Forms Image controlCurrently the Image control in Xamarin Forms does not have an event to handle when image could or couldn't open. <br />
I created a way to do this by extending the implementation for the Image control and ImageSource. <br />
Check out the source code and a demo app on my GitHub: <a href="https://github.com/nitescua/ImageExtensionsApp" target="_blank">https://github.com/nitescua/ImageExtensionsApp</a> <br />
I implemented two ways to handle image loaded status. You could either: <br />
1. Use the Image derived class ImageEx which exposes ImageOpened and ImageFailed events:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:7abd5366-00bb-4629-a0ee-3945021c5286" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 43px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"><</span><span style="color: black;">controls:ImageEx Source</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">http://dummyimage.com/100x100/000/fff</span><span style="color: maroon;">"</span><span style="color: black;"> ImageFailed</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Image_ImageFailed</span><span style="color: maroon;">"</span><span style="color: black;"> ImageOpened</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">Image_ImageOpened</span><span style="color: maroon;">"</span><span style="color: black;">/></span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<br />
<br />
2. Handle the status change right on the ImageSource instance: <br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:67f2e210-2dcc-4696-90c0-b77332c09cd2" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 57px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;">ImageSourceExtensions.SetStatusChangedHandler (MyImage.Source, (sender, status) </span><span style="color: black;">=></span><span style="color: black;"> {
Debug.WriteLine(</span><span style="color: maroon;">"</span><span style="color: maroon;">Image status: {0}</span><span style="color: maroon;">"</span><span style="color: black;">, status);
});
</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
where MyImage is an Image control in your Page <br />
<br />
To add the implementation in your apps, you need to:<br />
<br />
1. Add ImageSourceExtensions.cs and ImageEx.cs to your shared Xamarin Forms project<br />
<a href="https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp/Helpers/ImageSourceExtensions.cs">https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp/Helpers/ImageSourceExtensions.cs</a><br />
<a href="https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp/Controls/ImageEx.cs">https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp/Controls/ImageEx.cs</a><br />
<br />
2. Add the ImageLoaderSourceHandlerEx.cs in your platform specific code<br />
<br />
Android: <a href="https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.Droid/Renderers/ImageLoaderSourceHandlerEx.cs">https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.Droid/Renderers/ImageLoaderSourceHandlerEx.cs</a><br />
<br />
iOS: <a href="https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.iOS/Renderers/ImageLoaderSourceHandlerEx.cs">https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.iOS/Renderers/ImageLoaderSourceHandlerEx.cs</a><br />
<br />
WindowsPhone: <a href="https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.WinPhone/Renderers/ImageLoaderSourceHandlerEx.cs">https://github.com/andreinitescu/ImageExtensionsApp/blob/master/ImageExtensionsApp/ImageExtensionsApp.WinPhone/Renderers/ImageLoaderSourceHandlerEx.cs</a><br />
<br />
Few things you should be aware of:<br />
<br />
- the events are called when Uri is valid. So for example, it will work when uri is “http://xxxxx’ but not for ‘xxxxx’ <br />
- when using the ImageSource.StatusChangedHandler note that the event is called only if you set the ImageSource to an Image. It doesn’t work if you just create an ImageSource using ImageSource.FromXXX methods. You must set the ImageSource to an Image.<br />
<br />Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-37015864325774855622015-05-06T09:50:00.001-07:002018-12-07T23:07:02.558-08:00Cross platform splash screen in Xamarin Forms<br />
EDIT: I do not recommend this approach. Instead, use native approach to create splash screen because it shows much faster.<br />
<br />
<br />
If the splash screen is more than just an image, you can treat the splash screen as a Xamarin Page. <br />
To make this there are some steps:<br />
<br />
<strong>Step 1</strong>. set the App’s MainPage to the splash screen page: <br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:7162a143-5092-4060-8265-ea1658c22b2e" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 203px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">partial</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> App : Application
{
</span><span style="color: blue;">public</span><span style="color: black;"> App()
{
InitializeComponent();
Setup.Init();
</span><span style="color: green;">//</span><span style="color: green;"> with XLabs, you would do (Page)ViewFactory.CreatePage<SplashViewModel>();</span><span style="color: green;">
</span><span style="color: black;"> MainPage </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> SplashPage();
}
</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<br />
<br />
<strong>Step 2</strong>. In SplashPage, after some logic is done, you will need to “navigate” to your first app’s page. This means you just need to set again the App’s MainPage, i.e”:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:8f4b6884-9daa-4cdb-8d18-d9d164a5d4dd" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 89px; overflow: auto; width: 824px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;">
</span><span style="color: blue;">void</span><span style="color: black;"> ShowMainPage()
{
MainPage </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> SplashPage();
}</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
The issue is how do you call this. <br />
If you are not doing any logic in the splash screen, you can just do something like this:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:8a530e88-e97e-4521-ba34-41a384aa0ee3" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 220px; overflow: auto; width: 817px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> SplashPage : Page
{
async </span><span style="color: blue;">protected</span><span style="color: black;"> </span><span style="color: blue;">override</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> OnAppearing()
{
</span><span style="color: blue;">base</span><span style="color: black;">.OnAppearing();
await Task.Delay(TimeSpan.FromSeconds(</span><span style="color: purple;">2</span><span style="color: black;">));
</span><span style="color: green;">//</span><span style="color: green;"> again, here you might want to use instead XLab's ViewFactory.Create<FirstPageViewModel>()</span><span style="color: green;">
</span><span style="color: black;"> App.Current.MainPage </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> FirstPage();
}
}</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
If you are doing some logic in the view-model and you want to navigate to FirstPage, you don’t want to call this in the view-model.<br />
There are few ways to change the App’s MainPage without calling it from the view-model.<br />
<br />
You could use a messaging mechanism to send a custom message from the view-model to the view. Look to the Xamarin Form’s MessagingCenter: <a href="http://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/" title="http://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/">http://developer.xamarin.com/guides/cross-platform/xamarin-forms/messaging-center/</a>. <br />
<br />
Another way is, you probably are already using some navigation service to navigate between view-models, so what you need to do is have a custom navigation behavior in the way you navigate to the first page. With XLabs for example, you can define your own CustomNavigationService : XLabs.Platform.Services.INavigationService, override NavigateTo( ), then check for the page to which you navigate to, and if it’s FirstPage then create the NavigationPage and push the first page to it:<br />
<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:616af03b-ac9d-4751-859b-c3331d5fef7d" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 240px; overflow: auto; width: 814px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> CustomNavigationService : INavigationService
{
NavigationService navigationSvc;
</span><span style="color: blue;">public</span><span style="color: black;"> CustomNavigationService()
{
navigationSvc </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> NavigationService();
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> GoBack()
{
navigationSvc.GoBack();
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> GoForward()
{
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> NotImplementedException();
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> NavigateTo</span><span style="color: black;"><</span><span style="color: black;">T</span><span style="color: black;">></span><span style="color: black;">(</span><span style="color: blue;">object</span><span style="color: black;"> parameter </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">, </span><span style="color: blue;">bool</span><span style="color: black;"> animated </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">true</span><span style="color: black;">) </span><span style="color: blue;">where</span><span style="color: black;"> T : </span><span style="color: blue;">class</span><span style="color: black;">
{
NavigateTo(</span><span style="color: blue;">typeof</span><span style="color: black;">(T), parameter, animated);
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> NavigateTo(</span><span style="color: blue;">string</span><span style="color: black;"> pageKey, </span><span style="color: blue;">object</span><span style="color: black;"> parameter </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">, </span><span style="color: blue;">bool</span><span style="color: black;"> animated </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">true</span><span style="color: black;">)
{
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> NotImplementedException();
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> NavigateTo(Type pageType, </span><span style="color: blue;">object</span><span style="color: black;"> parameter </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">, </span><span style="color: blue;">bool</span><span style="color: black;"> animated </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">true</span><span style="color: black;">)
{
</span><span style="color: blue;">if</span><span style="color: black;"> (pageType </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: blue;">typeof</span><span style="color: black;">(MainViewModel))
{
var page </span><span style="color: black;">=</span><span style="color: black;"> (Page)ViewFactory.CreatePage(pageType);
App.Current.MainPage </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> NavigationPage (page);
navigationSvc </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> NavigationService(App.Current.MainPage.Navigation);
}
</span><span style="color: blue;">else</span><span style="color: black;">
{
navigationSvc.NavigateTo(pageType, parameter, animated);
}
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> RegisterPage(</span><span style="color: blue;">string</span><span style="color: black;"> pageKey, Type pageType)
{
navigationSvc.RegisterPage(pageKey, pageType);
}
}</span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<strong>Step 3.</strong> In Android, you need to configure few things:<br />
<br />
a. Define a startup theme and an app theme in your Resources\values\themes.axml:<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:1b1c958c-8beb-4be3-b3b1-4ea4b31703a5" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 239px; overflow: auto; width: 770px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;"><?</span><span style="color: black;">xml version</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">1.0</span><span style="color: maroon;">"</span><span style="color: black;"> encoding</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">utf-8</span><span style="color: maroon;">"</span><span style="color: black;"> </span><span style="color: black;">?></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">resources</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">color name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">splashscreencolor</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">#</span><span style="color: purple;">232323</span><span style="color: black;"></</span><span style="color: black;">color</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">style name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">StartUpAppTheme</span><span style="color: maroon;">"</span><span style="color: black;">
parent</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">android:Theme.Holo.Light</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">item name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">android:windowNoTitle</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: blue;">true</span><span style="color: black;"></</span><span style="color: black;">item</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">item name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">android:windowBackground</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">@color</span><span style="color: black;">/</span><span style="color: black;">splashscreencolor</span><span style="color: black;"></</span><span style="color: black;">item</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">style</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"><</span><span style="color: black;">style name</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">AppTheme</span><span style="color: maroon;">"</span><span style="color: black;">
parent</span><span style="color: black;">=</span><span style="color: maroon;">"</span><span style="color: maroon;">android:Theme.Holo.Light</span><span style="color: maroon;">"</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">style</span><span style="color: black;">></span><span style="color: black;">
</span><span style="color: black;"></</span><span style="color: black;">resources</span><span style="color: black;">></span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
<br />
b. In the native MainActivity, have the activity start with the Theme.Splash and then have it running with the AppTheme:<br />
<br />
<div class="wlWriterEditableSmartContent" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:f47dbec9-89c2-47dc-bb21-2f759542ef88" style="display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">
<pre style="background-color: silver; height: 239px; overflow: auto; width: 765px;"><div>
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: black;">[Activity(Theme </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: maroon;">"</span><span style="color: maroon;">@style/Theme.Splash</span><span style="color: maroon;">""</span><span style="color: maroon;">, MainLauncher = true, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize)]</span><span style="color: maroon;">
</span><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> MainActivity : FormsApplicationActivity
{
</span><span style="color: blue;">protected</span><span style="color: black;"> </span><span style="color: blue;">override</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> OnApplyThemeResource(</span><span style="color: blue;">global</span><span style="color: black;">::Android.Content.Res.Resources.Theme theme, </span><span style="color: blue;">int</span><span style="color: black;"> resid, </span><span style="color: blue;">bool</span><span style="color: black;"> first)
{
</span><span style="color: blue;">base</span><span style="color: black;">.OnApplyThemeResource(theme, Resource.Style.AppTheme, first);
}
...
} </span></div>
</pre>
<!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>
Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com1tag:blogger.com,1999:blog-18724657.post-79547996073248791602014-10-03T03:03:00.001-07:002014-10-03T03:03:19.037-07:00Configure app which requires admin rights to run at startup with task scheduler<p> </p> <p>App which requires elevated admin rights can’t just be set to run at startup by adding it to the registry key (<code><font face="Arial">HKLM\Software\Microsoft\Windows\CurrentVersion\Run) because it mail fail to start since it requires the UAC prompt. Windows will silently fail to display the UAC prompt.</font></code> <p><code><font face="Arial">One solution is to make the app a Windows Service, but depending on the technology used, this might not be possible. For example, a .NET Windows Service which is using .NET API printing (System.Printing) is not recommended (see <a title="http://blogs.msdn.com/b/dsui_team/archive/2013/06/24/printing-from-a-windows-service.aspx" href="http://blogs.msdn.com/b/dsui_team/archive/2013/06/24/printing-from-a-windows-service.aspx">http://blogs.msdn.com/b/dsui_team/archive/2013/06/24/printing-from-a-windows-service.aspx</a> or see ‘Caution’ in <a title="http://msdn.microsoft.com/en-us/library/system.drawing.aspx" href="http://msdn.microsoft.com/en-us/library/system.drawing.aspx">http://msdn.microsoft.com/en-us/library/system.drawing.aspx</a>).</font></code> <p><code></code><code><font face="Arial">So another solution is to use task scheduler.</font></code> <p><code></code>When configuring the scheduled task, you need to make sure: <p>1. In the task properties popup, "Run with highest privileges" option is checked. <p>2. In the "Edit Action" popup, "Start in" is filled with the directory path (Do not include quotation marks or a trailing slash) <p><a title="http://social.technet.microsoft.com/Forums/windows/en-US/7167bb31-f375-4f77-b430-0339092e16b9/how-does-run-with-the-highest-privileges-really-work-in-task-scheduler-?forum=w7itprogeneral" href="http://social.technet.microsoft.com/Forums/windows/en-US/7167bb31-f375-4f77-b430-0339092e16b9/how-does-run-with-the-highest-privileges-really-work-in-task-scheduler-?forum=w7itprogeneral">http://social.technet.microsoft.com/Forums/windows/en-US/7167bb31-f375-4f77-b430-0339092e16b9/how-does-run-with-the-highest-privileges-really-work-in-task-scheduler-?forum=w7itprogeneral</a> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-71969668268513060052014-09-02T04:42:00.001-07:002014-10-03T03:05:28.472-07:00Duplicate folders issue with MvvmCross by NuGet<p> </p> <p><strong><font style="background-color: #ffffff" color="#ff0000">EDIT: Issue is fixed in MVVMCROSS v3.2.1 !</font></strong></p> <p>With the current NuGet version of MvvmCross, when adding it to the project you get duplicate folders (‘Layout’ and ‘layout’, ‘Values’ and ‘values’)</p> <p>To fix this, right click on the project and choose ‘Tools \ Edit File’ in Xamarin Studio. In Visual Studio, there’s a similar way.</p> <p>In the .csproj, you just need to replace the first upper case letter with lower case letter, so replace ‘Layout’ with ‘layout’ and ’Values’ with ‘values’ and save the file.</p> <p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0KPGlANTtupN7ipWMM790OvCbIhb-A6o8oSi3B35DcpKqaFCVfSXv2Oj4wTfovPcbZjUDp2HXUK9MFSF37IftI1TGRnAPUwNyBkp49ETxdinEF-L2wWEquQunTryDikKjQegtAg/s1600-h/image%25255B4%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSCmnGLfzzpVBXPj8NA2A2yeb-L6xw0g_lj5-QOGbJ4WZz5Dz2E6go1XAGqepSKnyWJcD-L-CXVIzXi3cqQMscLzQS0SGihSe3aMgs2lhhwLSv_7NsDyciwTMBOu9qC6E5gV6I7w/?imgmax=800" width="702" height="293"></a></p> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-40802397057148234322014-08-05T05:31:00.001-07:002014-08-05T05:31:46.908-07:00Auto binding of outlets in Xamarin iOS and MvvmCross<p> </p> <p>If you are like me and you don’t like doing the bindings in code, you start thinking about solutions.</p> <p>So I’m experimenting with the idea of creating the bindings at runtime, based on a simple name convention:</p> <ul> <li>An UIButton outlet with the name 'btnXXX' is bound to the view-model 'XXXCommand' property.</li> <li>An UITextField outlet with the name 'txtXXX' is bound to the view-model 'XXX' property.</li> <li>An UILabel outlet with the name 'lblXXX' is bound to the view-model 'XXX' property.</li></ul> <p>For example, if you have a UIButton outlet called btnLogin, it's bound to view-model LoginCommand property.</p> <p>I uploaded the code here;</p> <p><a title="https://github.com/nitescua/AutoBinding/blob/master/README.md" href="https://github.com/nitescua/AutoBinding/">https://github.com/nitescua/AutoBinding/</a></p> <p>This can be done for other platforms as well.</p> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-70102458729676213282014-07-29T22:11:00.001-07:002014-07-29T22:11:56.820-07:00Xamarin HttpClient NameResolutionFailure exception<p> </p> <p>If you look on internet there are plenty of people reporting this error. </p> <p>Xamarin is somehow aware of this error, and it marked it as fixed but it doesn’t seem like it is.</p> <p>Fortunately, this exception appears only in debug mode, not in release mode.</p> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com2tag:blogger.com,1999:blog-18724657.post-73845254994343888102014-07-29T22:08:00.001-07:002014-07-29T22:08:45.225-07:00Android–deployment error - INSTALL_FAILED_UPDATE_INCOMPATIBLE<p><em></em> </p> <p>When trying to deploy on device I got this error:</p> <blockquote> <p><em>Deployment failed because of an internal error: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]</em></p> <p><em>Deployment failed. Internal error.</em></p></blockquote> <p>To fix it, run:</p> <p><em>C:\Users\[YourUserName]\AppData\Local\Android\android-sdk\platform-tools>adb uninstall com.xxx.yyy</em></p> <p>Don’t include the .apk file extension</p> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-68146522854954709992014-05-26T07:32:00.001-07:002014-05-26T07:33:34.529-07:00Publish empty folders<p> </p> <p>If you need to include an empty folder when deploying using MSDeploy (either manually from Visual Studio or calling msdeploy from scripts) you can do that by:</p> <p>1. create a Web Publishing Pipeline file (.wpp.targets)</p> <p> Create a new XML file in the project folder (the same folder that holds the .csproj or .vbproj file) and name it <projectname>.wpp.targets.</p> <p>2. Add the following</p> <p><em><?xml version="1.0" encoding="utf-8"?><br><Project ToolsVersion="4.0" xmlns="</em><a href="http://schemas.microsoft.com/developer/msbuild/2003""><em>http://schemas.microsoft.com/developer/msbuild/2003"</em></a><em>><br> <PropertyGroup><br> <AfterAddIisSettingAndFileContentsToSourceManifest>MakeEmptyFolders</AfterAddIisSettingAndFileContentsToSourceManifest><br> </PropertyGroup><br> <Target Name="MakeEmptyFolders"><br> <Message Text="Adding empty folder to hold downloads" /><br> <MakeDir Directories="$(_MSDeployDirPath_FullPath)\Survey\responses"/><br> </Target><br></Project></em></p> <p>In my case I needed an empty folder called ‘responses’ inside an existing ‘Survey’ folder.</p> <p>The folder will be created no matter which configuration or publishing profile is run.</p> <p>More info:</p> <p><a title="http://msdn.microsoft.com/en-us/library/ff398069(v=vs.110).aspx" href="http://msdn.microsoft.com/en-us/library/ff398069(v=vs.110).aspx">http://msdn.microsoft.com/en-us/library/ff398069(v=vs.110).aspx</a></p> <p><a title="http://blog.alanta.nl/2011/02/web-deploy-customizing-deployment.html" href="http://blog.alanta.nl/2011/02/web-deploy-customizing-deployment.html">http://blog.alanta.nl/2011/02/web-deploy-customizing-deployment.html</a></p> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-5370907470791913962014-04-07T06:05:00.001-07:002014-04-12T00:27:14.144-07:00A busy MvxViewController for MvvmCross + iOS<p>In my MVVMCross apps, in the shared PCL core library, I usually have a MvxViewModel derived class called ViewModelBase with a IsBusy property: </p> <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:06070efe-c101-4a40-bf79-99632e408e0f" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 809px; height: 254px;background-color:#E6E6E6;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;"><br /> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> ViewModelBase : MvxViewModel<br /> {<br /> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> isBusy; <br /> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> IsBusy <br /> { <br /> </span><span style="color: #0000FF;">get</span><span style="color: #000000;"> { </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.isBusy; } <br /> </span><span style="color: #0000FF;">set</span><span style="color: #000000;"> { </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.isBusy </span><span style="color: #000000;">!=</span><span style="color: #000000;"> value) { </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.isBusy </span><span style="color: #000000;">=</span><span style="color: #000000;"> value; </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.RaisePropertyChanged(</span><span style="color: #800000;">"</span><span style="color: #800000;">IsBusy</span><span style="color: #800000;">"</span><span style="color: #000000;">); } } <br /> }<br /><br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> other base stuff in ViewModelBase</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> }</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>The property is to update a progress indicator control in the view. <br>For iOS the control can be UIActivityIndicatorView.<br><br>But instead of placing a UIActivityIndicatorView on each view, we can dynamically create it at run-time when IsBusy property changes to true.<br>We can have this implemented in a ViewController base class like this: <br /><br /><div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:c2536ac2-dc0d-4fec-aa7f-944a6cb6fd2d" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 809px; height: 1312px;background-color:#E6E6E6;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF;">using</span><span style="color: #000000;"> System;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> System.ComponentModel;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> MonoTouch.ObjCRuntime;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> MonoTouch.UIKit;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> Cirrious.MvvmCross.Touch.Views;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> Cirrious.CrossCore.WeakSubscription;<br /></span><span style="color: #0000FF;">using</span><span style="color: #000000;"> YourApp.Core.ViewModels;<br /><br /></span><span style="color: #0000FF;">namespace</span><span style="color: #000000;"> YourApp.Touch<br />{<br /> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">abstract</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> MvxViewControllerBase : MvxViewController<br /> {<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> weak subscription to NotifyProperty event</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> IDisposable npSubscription;<br /><br /> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> ViewDidLoad()<br /> {<br /> </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.ViewDidLoad();<br /><br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> subscribe to view-model's PropertyChanged </span><span style="color: #008000;"><br /></span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.npSubscription </span><span style="color: #000000;">=</span><span style="color: #000000;"> ((INotifyPropertyChanged)</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.ViewModel).WeakSubscribe</span><span style="color: #000000;"><</span><span style="color: #0000FF;">bool</span><span style="color: #000000;">></span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">IsBusy</span><span style="color: #800000;">"</span><span style="color: #000000;">, (s, e) </span><span style="color: #000000;">=></span><span style="color: #000000;"> { </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.UpdateActivityIndicatorView(); });<br /> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> at this point view-model exists, so update the indicator view</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.UpdateActivityIndicatorView();<br /><br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> add other common UIViewController stuff</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> }<br /><br /> </span><span style="color: #0000FF;">protected</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> Dispose(</span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> disposing)<br /> {<br /> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (disposing </span><span style="color: #000000;">&&</span><span style="color: #000000;"> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.npSubscription </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)<br /> {<br /> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.npSubscription.Dispose();<br /> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.npSubscription </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">;<br /> }<br /> </span><span style="color: #0000FF;">base</span><span style="color: #000000;">.Dispose(disposing);<br /> }<br /><br /> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> UpdateActivityIndicatorView()<br /> {<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> get the activity indicator</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> var activityIndicatorView </span><span style="color: #000000;">=</span><span style="color: #000000;"> (UIActivityIndicatorView)</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.View.ViewWithTag(</span><span style="color: #800080;">1000</span><span style="color: #000000;">);<br /><br /> var vm </span><span style="color: #000000;">=</span><span style="color: #000000;"> (ViewModelBase)</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.ViewModel;<br /> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (vm.IsBusy)<br /> {<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> show busy indicator. create it first if it doesn't already exists</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (activityIndicatorView </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)<br /> {<br /> activityIndicatorView </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> UIActivityIndicatorView(</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.View.Frame)<br /> {<br /> ActivityIndicatorViewStyle </span><span style="color: #000000;">=</span><span style="color: #000000;"> UIActivityIndicatorViewStyle.Gray,<br /> Tag </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">1000</span><span style="color: #000000;"><br /> };<br /><br /> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.Add(activityIndicatorView);<br /> </span><span style="color: #0000FF;">this</span><span style="color: #000000;">.View.BringSubviewToFront(activityIndicatorView);<br /> activityIndicatorView.StartAnimating();<br /> }<br /><br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> show the activity indicator</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> activityIndicatorView.Hidden </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;<br /> }<br /> </span><span style="color: #0000FF;">else</span><span style="color: #000000;"><br /> {<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> hide the activity indicator</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (activityIndicatorView </span><span style="color: #000000;">!=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)<br /> {<br /> activityIndicatorView.Hidden </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;<br /> }<br /> }<br /> }<br /> }<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div>Instead of having a base class we can delegate the implementation to an extension class which has the same implementation.<br><br>Please let me know if you see any possible issues. <br><br>I am thinking to do a similar implementation for other platforms as well.<br>Maybe MVVMCross could support out of the box a similar implementation. A built in implementation in MVVMCross would probably require to be able to override the style for the indicator. <br /> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com1tag:blogger.com,1999:blog-18724657.post-48731547586624603002014-03-27T01:26:00.001-07:002015-05-23T00:40:00.418-07:00Sharing library project across solutions and NuGet<br />
<b>UPDATE</b>:<br />
Latest NuGet doesn't rely on 'Enable NuGet Package Restore’ feature: <a href="http://docs.nuget.org/docs/reference/package-restore">http://docs.nuget.org/docs/reference/package-restore</a><br />
So instead I recommend checking this: <a href="http://www.damirscorner.com/CategoryView,category,DevelopmentNuGet.aspx">http://www.damirscorner.com/CategoryView,category,DevelopmentNuGet.aspx</a><br />
<br />
I have several applications using one library where communication to the backend API is implemented.<br />
Here’s how the folder hierarchy for projects looks like<br />
Api<br />
Api.csproj<br />
Api.sln<br />
App1<br />
App1.csproj<br />
App1.sln<br />
App2<br />
App2.csproj<br />
App2.sln<br />
Each app solution (App1, App2) has Api.csproj added. <br />
The main reason why Api project is added to app solutions is we want to debug and step into the code of Api library easily.<br />
But this might not be a good idea because each app can depend on a specific version of the Api library. If something needs to be changed in the Api which affects all applications, all applications would need to be updated and sometimes the impact of the changes in the app is complex. <br />
For this reason, we might want to have each app depending on a specific version of the Api, so instead of adding the project as reference, we could add the compiled library as reference.<br />
We can solve the problem to step into the library source code by also having library.pdb files along with the .dll.<br />
More info:<br />
<a href="http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions" title="http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions">http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions</a><br />
<a href="http://blog.stangroome.com/2013/11/26/nuget-reference-paths-for-projects-in-multiple-solutions/" title="http://blog.stangroome.com/2013/11/26/nuget-reference-paths-for-projects-in-multiple-solutions/">http://blog.stangroome.com/2013/11/26/nuget-reference-paths-for-projects-in-multiple-solutions/</a> (see comment)<br />
<a href="http://blog.stangroome.com/2013/12/05/visual-studio-solutions-projects-and-shared-code/" title="http://blog.stangroome.com/2013/12/05/visual-studio-solutions-projects-and-shared-code/">http://blog.stangroome.com/2013/12/05/visual-studio-solutions-projects-and-shared-code/</a><br />
<a href="http://www.xavierdecoster.com/post/2011/11/16/why-everyone-should-be-using-a-symbol-server" title="http://www.xavierdecoster.com/post/2011/11/16/why-everyone-should-be-using-a-symbol-server">http://www.xavierdecoster.com/post/2011/11/16/why-everyone-should-be-using-a-symbol-server</a><br />
<a href="http://www.edsquared.com/2011/02/12/Source+Server+And+Symbol+Server+Support+In+TFS+2010.aspx" title="http://www.edsquared.com/2011/02/12/Source+Server+And+Symbol+Server+Support+In+TFS+2010.aspx">http://www.edsquared.com/2011/02/12/Source+Server+And+Symbol+Server+Support+In+TFS+2010.aspx</a><br />
<br />
However, suppose we still want to add the library as source code to app solutions.<br />
There’s a problem with NuGet that it’s creating ‘packages’ folder per solution.<br />
<a href="http://stackoverflow.com/questions/18376313/setting-up-a-common-nuget-packages-folder-for-all-solutions-when-some-projects-a" title="http://stackoverflow.com/questions/18376313/setting-up-a-common-nuget-packages-folder-for-all-solutions-when-some-projects-a">http://stackoverflow.com/questions/18376313/setting-up-a-common-nuget-packages-folder-for-all-solutions-when-some-projects-a</a><br />
Here’s how to do it:<br />
<ol>
<li>delete existing ‘package’ folder in each solution folder </li>
<li>for each solution, right-click on the solution file in the solution explorer > ‘Enable NuGet Package Restore’ </li>
<li>this will create a .nuget folder. open the NuGet.config </li>
<li>add the following under <configuration> node:<br /><config><br /> <add key="repositoryPath" value="../../packages" /><br /></config> (<b>NOTE</b>: if you're using Xamarin, you <u>MUST </u>use <b>forward </b>slashes, otherwise on Mac you will get a folder with the name '..\..\packages' !)<br />it instructs NuGet to use ‘packages’ folder located at the same level with Api and apps solution folders. <br />note that this path is relative to the location of NuGet.config file </li>
<li>go to each .csproj and make sure all paths which reference ‘packages’ folder are set to “..\..\packages’ </li>
<li>delete each ‘.suo’ file in solution folders </li>
<li>reopen Visual Studio </li>
<li>open each app solution and build it.<br />for the first solution being built, NuGet brings the packages in the new ‘packages’ folder.<br />all other solutions will reference the already downloaded packages</li>
</ol>
<div>
<br /></div>
<div>
References:</div>
<div>
http://forums.xamarin.com/discussion/17783/add-manage-nuget-packages-per-solution</div>
<div>
http://lastexitcode.com/blog/2014/08/10/NuGetSupportInXamarinStudio5-2/</div>
<div>
<br /></div>
Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-74512623724439268002014-03-14T03:24:00.001-07:002014-03-14T03:24:41.569-07:00Install GooglePlay in emulator<p> </p> <p>I am using the info from <a title="http://stackoverflow.com/questions/11154222/google-play-on-android-4-0-emulator" href="http://stackoverflow.com/questions/11154222/google-play-on-android-4-0-emulator#answer-11213598">http://stackoverflow.com/questions/11154222/google-play-on-android-4-0-emulator#answer-11213598</a></p> <p>1. Go to <a title="http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2" href="http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2">http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2</a> and get the latest .zip compatible with your target device. <br> Note the “Not compatible with x.x.x!” remarks</p> <p>2. Start your emulator:</p><pre><code>cd %LocalAppData%\Android\android-sdk\tools</code></pre><pre><code>emulator -avd VM_NAME_HERE -partition-size 500 -no-audio -no-boot-anim</code></pre><br /><p>Then use the following commands:<br /><p><code>cd %LocalAppData%\Android\android-sdk\platform-tools</code><pre><code># Remount in rw mode<br />adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system<br /><br /># Allow writing to app directory on system partition<br />adb shell chmod 777 /system/app<br /><br /># Install following apk<br />adb push GoogleLoginService.apk /system/app/.<br />adb push GoogleServicesFramework.apk /system/app/.<br />adb push Phonesky.apk /system/app/. # Vending.apk in older versions<br />adb shell rm /system/app/SdkSetup*</code></pre><pre><code></code> </pre> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-86119402755896024542014-01-25T15:56:00.001-08:002014-04-07T05:29:34.075-07:00Type-safe ViewModel to ViewModel navigation in MvvmCross<br />
In MvvmCross you can navigate between view-model's as described in the Wiki:<br />
<a href="https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation">https://github.com/MvvmCross/MvvmCross/wiki/ViewModel--to-ViewModel-navigation</a><br />
<br />
It's good however to use a simple type-safety mechanism.<br />
Suppose we have a ProductViewModel which expects two arguments for initialization:<br />
<br />
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> ProductViewModel : MvxViewModel
{
<span style="color: blue;">public</span> <span style="color: blue;">void</span> Init(<span style="color: blue;">int</span> productId, <span style="color: blue;">int</span> clientId)
{
....
}
}</pre>
<br /></div>
With a type-safe mechanism, instead of writing:<br />
<br />
<div>
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><b>ShowViewModel<ProductViewModel>(<span style="color: blue;">new</span> { productId = pid, clientId = cid });</b></pre>
</div>
<br />
we can write:<br />
<span style="background-color: #f4f4f4; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;"><br /></span>
<span style="background-color: #f4f4f4; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;"><b>NavigationHelper.ShowProduct(pid, cid);</b></span><br />
<div id="codeSnippetWrapper">
<br /></div>
<div>
where NavigationHelper is a simple utility class:</div>
<span style="background-color: #f4f4f4; color: blue; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;"><br /></span>
<span style="background-color: #f4f4f4; color: blue; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;">using</span><span style="background-color: #f4f4f4; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;"> Cirrious.CrossCore;</span><br />
<div>
<div>
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;">using</span> Cirrious.MvvmCross.ViewModels;
<span style="color: blue;">using</span> Cirrious.MvvmCross.Views;
<span style="color: blue;">using</span> MyApp.Core.ViewModels;
<span style="color: blue;">using</span> Cirrious.MvvmCross.Platform;
<span style="color: blue;">namespace</span> MyApp.Core.Common
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> NavigationHelper
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> ShowProduct(<span style="color: blue;">int</span> productId, <span style="color: blue;">int</span> clientId)
{
ShowViewModel<ProductViewModel>(<span style="color: blue;">new</span> { productId = productId, clientId = clientId });
}
<span style="color: blue;">static</span> <span style="color: blue;">void</span> ShowViewModel<T>(object parameter) <span style="color: blue;">where</span> T : IMvxViewModel
{
var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
var request = MvxViewModelRequest.GetDefaultRequest(<span style="color: blue;">typeof</span>(T));
request.ParameterValues = ((<span style="color: blue;">object</span>)parameter).ToSimplePropertyDictionary();
viewDispatcher.ShowViewModel(request);
}
}
}</pre>
</div>
<br />
<div>
<span style="color: blue; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;">using</span><span style="background-color: #f4f4f4; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt;"> Cirrious.MvvmCross.Platform;</span> namespace statement is important because it contains the <b>ToSimplePropertyDictionary()</b> extension method implemented by MvvmCross.</div>
<br />
Furthermore, instead of using the NavigationHelper class, we can move the ShowViewModel method to a ViewModelBase class:</div>
<br />
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> ViewModelBase : MvxViewModel
{
<span style="color: blue;">protected</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> ShowViewModel<T>(dynamic parameter) <span style="color: blue;">where</span> T : IMvxViewModel
{
var viewDispatcher = Mvx.Resolve<IMvxViewDispatcher>();
var request = MvxViewModelRequest.GetDefaultRequest(<span style="color: blue;">typeof</span>(T));
request.ParameterValues = ((<span style="color: blue;">object</span>)parameter).ToSimplePropertyDictionary();
viewDispatcher.ShowViewModel(request);
}
}
<span style="color: blue; font-size: 8pt; line-height: 12pt;">public</span><span style="font-size: 8pt; line-height: 12pt;"> </span><span style="color: blue; font-size: 8pt; line-height: 12pt;">class</span><span style="font-size: 8pt; line-height: 12pt;"> ProductViewModel : ViewModelBase</span>
{
<span style="color: blue;">public</span> <span style="color: blue;">static</span> Show(<span style="color: blue;">int</span> productId, <span style="color: blue;">int</span> clientId)
{
ShowViewModel<ProductViewModel>(<span style="color: blue;">new</span> { productId = productId, clientId = clientId });
}
<span style="color: blue;"> public</span> <span style="color: blue;">void</span> Init(<span style="color: blue;">int</span> productId, <span style="color: blue;">int</span> clientId)
{
...
}
}</pre>
<br /></div>
and we can now write:<br />
<br />
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="background-color: #f4f4f4; border-bottom-style: none; border-left-style: none; border-right-style: none; border-top-style: none; color: black; direction: ltr; font-family: 'Courier New', courier, monospace; font-size: 8pt; line-height: 12pt; margin: 0em; overflow: visible; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left; width: 100%;">ProductViewModel.Show(pid, cid);</pre>
<br />
Having the Show method near the Init method in the ViewModel class, makes it a bit more easier to maintain the parameters.</div>
Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-78981973950254092502014-01-18T02:08:00.001-08:002014-01-18T03:16:40.621-08:00ASP.NET errors<p> </p> <p><strong>#1. There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined</strong></p> <blockquote> <p>Check .NET Framework version for app pool.</p> <p>Projects developed in (2.0,3.0,3.5) should run under an Application Pool with .NET FRAMEWORK VERSION v2.0.50727 <p>Projects developed in 4.0 should run under an Application Pool with .NET FRAMEWORK VERSION v4.0.30319</p></blockquote> <p><strong>#2. Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.</strong> <blockquote> <p>Make sure that "Enable 32 - Bit Applications" is set to false or true for the app pool, depending on <code>System.Data.SQLite.dll</code> <p><code>System.Data.SQLite.dll</code> is a mixed assembly, i.e. it contains both managed code and native code. Therefore a particular <code>System.Data.SQLite.dll</code> is either x86 or x64, but never both.</p></blockquote> <h5>#3. HTTP Error 404.3 - Not Found</h5> <h6>The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.</h6> <p>Requested URL<br> <a href="http://localdev.site.com/Webservices/UserProviderService.svc">http://localdev.site.com/Webservices/UserProviderService.svc</a> <blockquote> <p>You need to run this: <a title="http://enginecore.blogspot.ro/2013/06/svc-handling-in-iis.html" href="http://enginecore.blogspot.ro/2013/06/svc-handling-in-iis.html">http://enginecore.blogspot.ro/2013/06/svc-handling-in-iis.html</a></blockquote> Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com0tag:blogger.com,1999:blog-18724657.post-41588711447507965402014-01-16T10:45:00.001-08:002014-01-28T01:15:52.221-08:00Invalid markup in XAML in Visual Studio 2013<br />
If you get this error in designer when there’s clearly no error in your XAML:<br />
- close all files open in Visual Studio<br />
- close Visual Studio<br />
- delete the .suo file near the .sln<br />
- delete bin and obj folders<br />
<br />
if still doesn't work you can try to delete all directories from:<br />
<strong>%LocalAppData%\Microsoft\VisualStudio\12.0\Designer\ShadowCache</strong><br />
<br />
More info:<br />
<a href="http://stackoverflow.com/questions/12871358/visual-studio-2012-xaml-designer-invalid-markup">http://stackoverflow.com/questions/12871358/visual-studio-2012-xaml-designer-invalid-markup</a><br />
<a href="http://forums.xamarin.com/discussion/10284/xamarin-new-pcls-w8-wp8-net45-xamarin-ios-xamarin-droid-plus-new-microsoft-bcl-terribly-broken">http://forums.xamarin.com/discussion/10284/xamarin-new-pcls-w8-wp8-net45-xamarin-ios-xamarin-droid-plus-new-microsoft-bcl-terribly-broken</a>Andrei Nitescuhttp://www.blogger.com/profile/17106850549627677414noreply@blogger.com4