<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Avivo Tech Blog &#187; Silverlight/WPF</title>
	<atom:link href="http://tech.avivo.si/category/silverlight-wpf/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.avivo.si</link>
	<description>Solving problems</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:46:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>The easiest way to generate a QR Code for software developers</title>
		<link>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-easiest-way-to-generate-a-qr-code-for-programmers</link>
		<comments>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 14:46:11 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HTML, Javascript and CSS]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[qr code generators]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1445</guid>
		<description><![CDATA[So you want to simply generate a QR Code image without diving into the technical specifics? This blog post contains a few simple examples. Just copy-paste where you need it. Idea is to build a URL, make an HTTP request and download the QR Code image. Result is the following image: HTTP Request URL looks [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to simply generate a QR Code image without diving into the technical specifics? This blog post contains a few simple examples. Just copy-paste where you need it.</p>
<p>Idea is to build a URL, make an HTTP request and download the QR Code image. Result is the following image:</p>
<pre><img src="http://www.esponce.com/api/v3/generate?content=your%20content%20goes%20here&#038;format=png" alt="your content goes here" /></pre>
<h2>HTTP Request</h2>
<p>URL looks like<strong> http://www.esponce.com/api/v3/generate?content={content}&amp;format={format}</strong> where <strong>{content}</strong> is URL encoded content to be embedded in QR and <strong>{format}</strong> is output image format. Available formats are <strong>png, jpg, bmp, tif, xaml, svg, eps, txt, html, zip</strong> (containing all listed formats)</p>
<p>List of other parameters like color and size can be found <a href="http://www.esponce.com/help/api-v3/generate#parameters">here</a>.</p>
<h2>C# Sample</h2>
<p>This code can be used in <strong>.NET 2.0</strong> including ASP.NET and WPF or <strong>Silverlight</strong> for web or <strong>WP7</strong></p>
<pre class="brush: csharp; title: ; notranslate">
using System;
using System.IO;
using System.Web;
using System.Net;

public class Program
{
  public static void Main(string[] args)
  {
    //Generate a QR Code and save it to file &quot;sample.png&quot;
    Generate(&quot;your content goes here&quot;, &quot;png&quot;, &quot;sample.png&quot;);
  }

  public static void Generate(string content, string format, string path)
  {
    string encoded = HttpUtility.UrlEncode(content);
    Uri uri = new Uri(&quot;http://www.esponce.com/api/v3/generate?content=&quot; + encoded + &quot;&amp;format=&quot; + format);
    WebClient client = new WebClient();
    client.DownloadFile(uri, path);
  }
}
</pre>
<h2>Java Sample</h2>
<p>This code can be used in a classic <strong>Java</strong> application or web <strong>applet</strong> or <strong>Android</strong> application</p>
<pre class="brush: java; title: ; notranslate">
import java.io.*;
import java.net.*;

public class qrcode
{
  public static void main(String args[])
  {
    //Generate a QR Code image and save it to file &quot;sample.png&quot;
    generate(&quot;your content goes here&quot;, &quot;png&quot;, &quot;sample.png&quot;);
  }

  public static void generate(String content, String format, String path)
  {
    try
    {
      String encoded = URLEncoder.encode(content, &quot;UTF-8&quot;);
      String url = &quot;http://www.esponce.com/api/v3/generate?content=&quot; + encoded + &quot;&amp;format=&quot; + format;
      BufferedInputStream ins = new BufferedInputStream(new URL(url).openStream());
      FileOutputStream fos = new FileOutputStream(path);
      BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

      int size = 0;
      byte data[] = new byte[1024];
      while ((size = ins.read(data, 0, 1024)) &amp;gt; 0)
      {
        bos.write(data, 0, size);
      }

      bos.close();
      fos.close();
      ins.close();
    }
    catch (Exception e)
    {
    }
  }
}
</pre>
<h2>Python Sample</h2>
<p>Using Python 2.7</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import urllib
import httplib

def generate(content, format = &quot;png&quot;):
    query = urllib.urlencode({ &quot;content&quot;: content, &quot;format&quot;: format })
    con = httplib.HTTPConnection(&quot;www.esponce.com&quot;)
    con.request(&quot;GET&quot;, &quot;/api/v3/generate?&quot; + query)
    response = con.getresponse()
    image = response.read()
    con.close()
    return image

image = generate(&quot;your content goes here&quot;)
file = open(&quot;sample.png&quot;, &quot;wb&quot;)
file.write(image)
file.close()
</pre>
<h2>JavaScript Sample</h2>
<p>JavaScript in combination with HTML</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;img id=&quot;qrcode&quot; src=&quot;&quot; alt=&quot;QR Code&quot; /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    function generate(content)
    {
        var url = &quot;http://www.esponce.com/api/v3/generate?content=&quot; + encodeURI(content) + &quot;&amp;format=png&quot;;
        var img = document.getElementById(&quot;qrcode&quot;);
        img.src = url;
    }
    generate(&quot;your content goes here&quot;);
&lt;/script&gt;
</pre>
<h2>PHP Sample</h2>
<pre class="brush: php; title: ; notranslate">
&lt;img src=&quot;&lt;?php echo generate(&quot;your content goes here&quot;); ?&gt;&quot; alt=&quot;QR Code&quot; /&gt;

&lt;?php
function generate($content, $format = &quot;png&quot;)
{
    $encoded = urlencode($content);
    $url = &quot;http://www.esponce.com/api/v3/generate?content=$encoded&amp;format=$format&quot;;
    return $url;
}
?&gt;
</pre>
<h2>There is more</h2>
<p>Download all samples with <em>make</em> script <a href="http://tech.avivo.si/wp-content/uploads/2012/01/generate-qr-code-samples-src.zip">here</a>.</p>
<p>Other QR Code related methods like decoding (reverse process of generating) and tracking scans can be found at <a href="http://www.esponce.com/help">esponce.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2012/01/the-easiest-way-to-generate-a-qr-code-for-programmers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set IIS binding manually (add and remove IIS binding)</title>
		<link>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=set-iis-binding-manually-add-and-remove-iis-binding</link>
		<comments>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 14:22:57 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[adding binding to iis from command line]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[change iis bindings from asp.net mvc website]]></category>
		<category><![CDATA[iis 7]]></category>
		<category><![CDATA[iis bindings]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1422</guid>
		<description><![CDATA[We had an issue that we need to add or remove IIS 7 or IIS 7.5 additional bindings on one web application and we wanted to do this from one of our ASP.NET MVC applications. It is possible so you need to use IIS system program appcmd.exe (you can find it in C:\Windows\System32\inetsrv\ (we suggest [...]]]></description>
			<content:encoded><![CDATA[<p>We had an issue that we need to add or remove IIS 7 or IIS 7.5 <strong>additional bindings</strong> on one web application and we wanted to do this from one of our ASP.NET MVC applications.</p>
<p>It is possible so you need to use IIS system program <strong>appcmd.exe</strong> (you can find it in <strong>C:\Windows\System32\inetsrv\</strong> (we suggest you to put this into your PATH variable)</p>
<h3><strong>Adding additional bindings</strong></h3>
<p>You want to add <strong>your</strong><strong>-subdomain.your-domain.com</strong> binding to your IIS 7 app named <strong>your-domain.com</strong></p>
<p><span style="color: #ff0000;">C:\Windows\System32\inetsrv\appcmd set site /site.name: <strong>your-domain.com</strong> /+bindings.[protocol='http',bindingInformation='*:80:<strong>your-subdomain.your-domain.com</strong>']</span></p>
<h3><strong>Removing existing bindings</strong></h3>
<p>You want to <strong>remove </strong><strong>your</strong><strong>-subdomain.your-domain.com</strong> binding from your IIS 7 app named <strong>your-domain.com </strong>(please notice <strong>- sign</strong> in front of <strong>bindings </strong>word)<strong><br />
</strong></p>
<p><span style="color: #ff0000;">C:\Windows\System32\inetsrv\appcmd set site /site.name: <strong>your-domain.com</strong> /-bindings.[protocol='http',bindingInformation='*:80:<strong>your-subdomain.your-domain.com</strong>']</span></p>
<p>And that&#8217;s it but if you want to run it from ASP.NET you could try to use Process and ProcessInfo classes to run DOS command but there are some permissions problems (we didn&#8217;t investigated much).</p>
<p>Other (alternative way that we tried is directly from the code)<br />
You will need to reference this DLL: <strong>c:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll </strong></p>
<pre>using (ServerManager serverManager = new ServerManager())
{
  if (serverManager.Sites == null)
    throw new SimpleException("There are no IIS applications!");

  var esponceApp = serverManager.Sites.FirstOrDefault(
x =&gt; x.Name == Settings.IISAppName);
  if (esponceApp != null)
  {
    BindingCollection bindingCollection = esponceApp.Bindings;
    Binding binding = bindingCollection.CreateElement("binding");
    binding["protocol"] = "http";
    binding["bindingInformation"] =
string.Format(@"{0}:{1}:{2}", "*", "80", this.DomainName);

    //Remove this binding if already exists.
    int oldBindingIndex = -1;
    int bindingIndex = -1;
    foreach (Binding currentBinding in esponceApp.Bindings)
    {
      if (currentBinding.BindingInformation ==
binding["bindingInformation"].ToString())
      {
        bindingIndex = esponceApp.Bindings.IndexOf(currentBinding);
      }
      if (!string.IsNullOrEmpty(oldDomainName) &amp;&amp;
      currentBinding.BindingInformation ==
string.Format(@"{0}:{1}:{2}", "*", "80", oldDomainName))
      {
        oldBindingIndex = esponceApp.Bindings.IndexOf(currentBinding);
      }
    }
    if (bindingIndex != -1)
    {
      esponceApp.Bindings.RemoveAt(bindingIndex);
    }
    if (oldBindingIndex != bindingIndex &amp;&amp; oldBindingIndex != -1)
    {
      esponceApp.Bindings.RemoveAt(oldBindingIndex);
    }

    //Add this bindings
    bindingCollection.Add(binding);
    serverManager.CommitChanges();
  }
}
}
catch
{
throw new SimpleException("Could not add binding into IIS application!");
}</pre>
<p>Important!<br />
Set identity of your app&#8217;s <strong>Application Domain</strong> from <strong>Advanced Settings &gt; Process Model &gt; Identity &gt; Change &#8220;ApplicationPoolIdentity&#8221; to &#8220;Local System&#8221;</strong></p>
<p>Investigate also security implications if you are not running this in Intranet&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/12/set-iis-binding-manually-add-and-remove-iis-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight: Equidistant items in a stack panel</title>
		<link>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silverlight-xaml-equidistant-items-in-a-stack-panel</link>
		<comments>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 13:00:28 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[axis]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[equidistant]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[stackpanel]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1164</guid>
		<description><![CDATA[This post describes how to align items in a container so the two neighbour items are always aligned with equal distance. Solution should be flexible, meaning that when items are changed or when container is resized items should keep equal distance in between. Reader should have some basic knowledge about C# and XAML for Silverlight. [...]]]></description>
			<content:encoded><![CDATA[<p>This post describes how to align items in a container so the two neighbour items are always aligned with equal distance. Solution should be flexible, meaning that when items are changed or when container is resized items should keep equal distance in between. Reader should have some basic knowledge about C# and XAML for Silverlight.</p>
<h2>Ideas</h2>
<ul>
<li>using Canvas and positioning items with <strong>absolute coordinates</strong> &#8211; items are always fixed, coordinates need to be calculated, so it is the least flexible approach, no</li>
<li>using <strong>StackPanel</strong> with items that have margin &#8211; margins need to be recalculated when an item is added or removed or when container is resized, maybe</li>
<li>using Grid with <strong>predefined rows and columns</strong> &#8211; notice <em>predefined</em>, means less flexibility, but offers equal size rows/columns, maybe</li>
<li>using a <strong>custom control</strong> &#8211; making Grid more dynamic but extending number of rows/columns when items are added, yes</li>
</ul>
<h2>Custom Control: EqualDistanceStackPanel</h2>
<p>As written before, custom control should extend Grid to become more flexible</p>
<pre style="background: #eeeeee; padding: 15px;">public class EqualDistanceStackPanel : Grid
{
}</pre>
<p>&nbsp;</p>
<p><em>EqualDistanceStackPanel</em> should implement <em>ItemsSource</em> and <em>ItemTemplate</em> just like <em><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol%28v=vs.95%29.aspx" target="_blank">ItemsControl</a></em></p>
<pre style="background: #eeeeee; padding: 15px;">#region ItemsSource
public IEnumerable ItemsSource
{
  get { return (IEnumerable)GetValue(ItemsSourceProperty); }
  set { SetValue(ItemsSourceProperty, value); }
}

public static readonly DependencyProperty ItemsSourceProperty =
  DependencyProperty.Register("ItemsSource", typeof(IEnumerable),
  typeof(EqualDistanceStackPanel), new PropertyMetadata(ItemsSourceChanged));

private static void ItemsSourceChanged(DependencyObject d,
  DependencyPropertyChangedEventArgs e)
{
  var panel = d as EqualDistanceStackPanel;
  if (panel != null)
  {
    if (e.OldValue != null)
    {
      panel.ClearItems();
    }
    if (e.NewValue != null)
    {
      panel.BindItems(e.NewValue as IEnumerable);
    }
  }
}
#endregion

public DataTemplate ItemTemplate
{
  get;
  set;
}</pre>
<p>&nbsp;</p>
<p><em>ClearItems</em> method deletes all previous elements from the panel and <em>BindItems</em> attaches fresh controls from item template.</p>
<pre style="background: #eeeeee; padding: 15px;">protected void ClearItems()
{
  this.Children.Clear();
}

protected void BindItems(IEnumerable items)
{
  if (this.ItemTemplate == null)
  {
    return;
  }

  //Create and attach children
  foreach (var item in items)
  {
    var element = this.ItemTemplate.LoadContent() as FrameworkElement;
    element.DataContext = item;
    this.Children.Add(element);
  }

  //Realign in container
  Refresh();
}</pre>
<p>&nbsp;</p>
<p>How should the custom control look in XAML? <em>EqualDistanceStackPanel</em> gets a collection of items, e.g. of UIElement type.</p>
<pre style="background: #eeeeee; padding: 15px;">&lt;Grid xmlns:c="clr-namespace:Avivo.Controls"&gt;
  &lt;c:EqualDistanceStackPanel ItemsSource="{Binding Items}" Orientation="Vertical"&gt;
    &lt;c:EqualDistanceStackPanel.ItemTemplate&gt;
      &lt;DataTemplate&gt;
        &lt;ContentPresenter Content="{Binding}" /&gt;
      &lt;/DataTemplate&gt;
    &lt;/c:EqualDistanceStackPanel.ItemTemplate&gt;
  &lt;/c:EqualDistanceStackPanel&gt;
&lt;/Grid&gt;</pre>
<p>&nbsp;</p>
<h2>Example</h2>
<p>Ruler has been made to demonstrate the usage of EqualDistanceStackPanel. Numbers are bound to the control and ticks are bound to another control using the same binding collection. Left image represents container height 300px and right when resized to 460px &#8211; elements are automatically aligned with equal distance.<br />
<img class="alignnone size-full wp-image-1177" title="Example of a ruler" src="http://tech.avivo.si/wp-content/uploads/2011/01/equidistant-stack-panel.jpg" alt="" width="414" height="734" /></p>
<p><a href="http://labs.avivo.si/equidistant/" target="_blank">Try demo</a>, resize browser to see the effect. This control has been originally developed for custom chart axes in <a href="http://qrcode.good-survey.com/" target="_blank">QR Code Statistics</a> application. <em>EqualDistanceStackPanel</em> control is lightweight, works for the statistics application and should be improved for general usage.</p>
<h2>Source code</h2>
<ul>
<li><a href="http://labs.avivo.si/equidistant/EqualDistanceStackPanel.zip">Source code</a>, Visual Studio sample Silverlight and web project</li>
</ul>
<h2>References</h2>
<ul>
<li><a href="http://chris.59north.com/post/Using-DataTemplates-in-custom-controls.aspx" target="_blank">Using DataTemplates in custom controls</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2011/03/silverlight-xaml-equidistant-items-in-a-stack-panel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash vs Silverlight</title>
		<link>http://tech.avivo.si/2010/12/flash-vs-silverlight/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flash-vs-silverlight</link>
		<comments>http://tech.avivo.si/2010/12/flash-vs-silverlight/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 16:51:32 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[superia]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=1018</guid>
		<description><![CDATA[We at Avivo thought that we should post something about Silverlight vs. Flash as we use both technologies at our work. We always want to explore different techniques in production to bring out innovative approach for each project and to inspire our clients. This post is about choosing right technologies when dealing with interactive or [...]]]></description>
			<content:encoded><![CDATA[<table bgcolor="#efeded">
<tbody>
<tr>
<td style="padding: 7px; padding-bottom: 7px; font-family: Georgia; font-size: 15px; line-height: 21px;">We at Avivo thought that we should post something about Silverlight vs. Flash as we use both technologies  at our work. We always want to explore different techniques in production to bring out innovative approach for each project and to inspire our clients.</td>
</tr>
</tbody>
</table>
<div style="padding-top: 10px;"><img class="alignnone size-large wp-image-1025" title="flash-vs-silverlight" src="http://tech.avivo.si/wp-content/uploads/2010/12/flash-vs-silverlight-700x301.jpg" alt="" width="700" height="301" /></div>
<p>This post is about choosing right technologies when dealing with interactive or animated content on the web. It is a our test of Silverlight and Flash technology and we will describe our experience working with both of them. For the record: »HTML5 is not being part of experiment«.</p>
<h2>Adobe Flash</h2>
<p>Flash is well known as being the tool for animations and able to bring all kind of interactive content on web. Flash golden era of  last decade is coming to an end. Currently web site trends are banning Flash out for many different reasons. First was <a href="http://jquery.com/">jQuery</a> that started to replace Flash in many simple tasks and HTML5 will probably be the final executor. Then, also <a href="http://www.apple.com" target="_blank">Apple </a>announced that it will not support Flash on iPhone/iPad. Nevertheless Flash will stay around long time especially when you want to bring extremely good interactivity inside browser for smaller parts like games or banners and for such specifics tasks Flash is still without competition.</p>
<h2>Microsoft Silverlight</h2>
<p>On the other side Silverlight was many times quoted as <a href="http://www.lynnfredricks.com/2010/11/01/microsofts-silverlight-no-longer-a-flash-competitor/">Flash competitor but not any more</a> and lately is obvious that has many other advantages like delivering best video quality/performance and out of browser experience. And developing in C#/VB/other dynamic languages and reusing the code naturally with the project and through the projects. Speed, frame rate accuracy and low CPU usage give few good strengths to the Silverlight down the road. Nowadays that Silverlight is used also as platform for <a href="http://www.microsoft.com/windowsphone/en-gb/default.aspx">Windows Phone</a> we think Silverligt is more attractive then ever.</p>
<h2>Both are RIA</h2>
<p>We need to mentioned that also many Flash developers didn&#8217;t want to switch to Silverligt and many reasons why they didn&#8217;t are very clear to us. To say it in short: Silverlight demands new approach that Flash developers just can&#8217;t or not willing to adopt. When you converting you have to convert fully to have chance for success. Only then you are comfortable enough to work with Silverlight and you are on better position to decide what would be the best technology for specific given task.</p>
<p>Nice example is <a href="http://www.shinedraw.com/flash-vs-silverlight-gallery/ ">Shine Draw web site</a> where each animated example is done in both technologies.  Our task was to bring out animated effect as good as it is possible to be smooth and visual attractive. We decided that this can be good example to try both technologies out and at the same time we was also eager to test them both.</p>
<p><!-- Silverlight vs. Flash: Which technology are you using at your work?  --><br />
<!--<script src="http://www.good-survey.com/poll/e35aq46sw25r.js" type="text/javascript"></script>--></p>
<h2>Our project</h2>
<p>We wanted to create appealing visual effect of  changing triangular pattern animation as best as it gets with bit of 3D look and feel. We made grid out of triangles and we wanted to transform grid while changing images with seamless transitions.</p>
<div style="padding: 10px 0 3px 0;"><img class="alignnone size-large wp-image-1026" title="pattern" src="http://tech.avivo.si/wp-content/uploads/2010/12/pattern1-700x178.jpg" alt="" width="700" height="178" /></div>
<p><span style="color: #7f7f7f; font-size: 12px;">Design ready to animate. Skip reading and see final result <a title="Flash vs Silverlight - Superia pattern" href="http://labs.avivo.si/flash-vs-silverlight/" target="_blank">here</a>.<span> </span></span></p>
<h2>Pattern design ready to animate</h2>
<p>The goal was to animate 6 different pattern designs with seamless transformations with use of 3D on each triangular element.</p>
<div style="padding: 10px 0 3px 0;"><img class="alignnone size-large wp-image-1027" title="patterns" src="http://tech.avivo.si/wp-content/uploads/2010/12/patterns-700x397.jpg" alt="" width="700" height="397" /></div>
<h2>First try with Silverlight</h2>
<p>We had experience with Silverlight transitions while working on <a href="http://www.youtube.com/avivotube#p/u/7/-Mltdr75ecQ">Superia Player</a> and process was very natural and very quick from start to finished.  When we wanted to bring even more interesting 3D transformation on irregular triangles positioned grid parts we encounter issues and we decide is time to switch to Flash and repeat the process.</p>
<h3>Input parameters</h3>
<p>Using 'initParams' in HTML input parameters are passed to Silverlight application. Application collects the parameters on load and requests the specified pattern XML file and initial image from the hosting server. Each other image is loaded once on demanded and cached by browser.</p>
<h3>Mapping images to triangles</h3>
<p>Triangle vector objects were created dynamically by the pattern defined in XML and they fit to the container size. Application has been developed in Silverlight 3 which has no native 3D support but already supports graphic acceleration. So triangles are drawn in 2D space faking the 3D look, 2D is also used because of better performance. Images are mapped to triangles by calculating rotation and offset using ImageBrush that could be later replaced by VideoBrush allowing to map video frames. Lot of geometrical math was done to do this job.</p>
<h3>Flip animations</h3>
<p>Triangle flip animation was done in two ways: transforming around diagonal centre point or transforming vertically/horizontally. In either way front side hides and back side shows or vice versa resulting in image change. Since the triangles are drawn on 2D spaces animations are faking 3D transitions by scaling, skewing, rotating, translating and remapping image. Animation can flip triangles progressively from the top left corner towards the bottom right. Another more appropriate animation starts flipping random triangles progressively with short delays between phases.</p>
<h3>Hosting Silverlight</h3>
<p>Silverlight is embedded in HTML using 'object' tag and 'params'. Setting parameters is straightforward, no tricks or work-arounds. Additionally HTML content can be inserted into 'object' allowing user to view the alternative content in case Silverlight is not installed or plug-in not enabled in browser.</p>
<h3>The catch</h3>
<p>Working with 2D, drawing triangles and mapping parts of image may seem easy at the beginning but when it goes towards fake 3D rotations it can get complex. Having multiple layers, calculating offsets and transitions, mapping images, switching images (front/back) during animation, generating animations, generating delays between flip... Finally algorithms get too complex to continue in 2D space without real 3D engine.</p>
<h2>Making Flash pattern</h2>
<p>We knew that flash might be better shaping irregular transformation but one thing we need to know is that Flash until recently didn't have direct 3D support. Sure, you could make it your own 3D effect by using math to calculate 2D movement and rotation in such way that would resembles 3D feeling, also we need to mentioned that out there are many excellent package of 3D utilities and one is called <a href="http://blog.papervision3d.org/" target="_blank">Paper Vision 3D</a> that was and is still used to produce nice 3D effects in Flash. But we were up to try something (relatively) new and besides that, we wanted to see what can be done with Flash-only 3D in Flash CS4 version.     </p>
<p><strong>Creating our triangular pattern animation required a few critical parts of AS3 code:</strong></p>
<ul>
<li>Loading XML data for pattern definition</li>
<li>Loading images used to create pattern</li>
<li>Mapping images to triangles</li>
<li>Animating the actual transitions</li>
</ul>
<h3>Pattern XML data</h3>
<p>Since introduction of AS3, handling XML data in Flash has become much, much, less complicated, thanks to the adoption of ECMAScript for XML (E4X). Now XML acts as native data type, you don't need to create special objects to copy data from XML.   Now data from XML is directly accessible from XML object, using actual element and attribute names to select appropriate data form XML. Picture preloading is also now much more simple, although the "art-of-preloading" was conquered long ago, classes used to load external content are now better organized, and callback functions for various events that can happen during load are now handled by proper event listeners.</p>
<p>Another good thing in AS3 is that every DisplayObject is by default invisible until you explicitly add it to some other, visible or DisplayObject as it's child. So you can do any kind of manipulation of size, position, alpha, and so on, until you decide that your object is finally in a state you want it to appear on stage.  Sticking images on triangle parts Applying pictures to triangles was another task to perform even before we could use 3d effects. Although it takes a bit of math to draw triangles on proper locations, it is still a combination of well-known lineTo, moveTo, curveTo methods (if you want triangles with rounded corners) and even better in newer version of Flash, you can now use drawPath method. Performance in drawing should be better as well as precision.</p>
<h3>Using 3D in Flash</h3>
<p>With all this we had the basic setup completed, and we came to the funny parts, exploring 3d effects. Using 3d in Flash has become quite easy, you can set rotationX, rotationY, rotationZ, and x, y, z values for any visible objects. Tweening any of these properties will create 3d animation effect. Nice and easy.   Of course, some experimentation was needed, to get some idea how change z value effects the object, its appearance in the stack of objects. Any sudden and extreme change of z value will produce quite unnatural effect.     </p>
<p>Unfortunately, there must be a glitch, when 3d engine is activated (that is when you change any property that directly or indirectly changes z property of an object) the object itself is immediately blurred and this is bad for display animation. In fact, the object is bitmap-cached (to make animation easily to compute) with smoothing. Usually that is not a big deal, unless, as it was the case with our pattern, you need very precise positioning of some elements and crystal sharp edges.</p>
<p><img src="http://tech.avivo.si/wp-content/uploads/2010/12/patter-blur-edges-and-fixing-timers-700x220.jpg" alt="" title="patter-blur-edges-and-fixing-timers" width="700" height="220" class="alignnone size-large wp-image-1107" /><br />
<span style="color: #7f7f7f; font-size: 12px;">Blur edges and timers were pian in the ass.</span></p>
<h3>Solving problems with 3D to 2D world</h3>
<p>This has becomes a first major problem with our pattern project and solution isn't easily at least not in all circumstances. Luckily for our pattern, we struck such a layout that we could overcome this. To make elements clear, once you used 3d effect on an object it will be bitmap cached and blurred, and there's nothing you can do about it. But if your animation is such that in the end your object is in such position that any z-axes related property is zero-ed, you can bring you object back to the 2d world.</p>
<h3>How Flash is transforming</h3>
<p>The thing is, Flash uses two different transformation matrices to track 2d and 3d properties of an object. If 3d transformation matrix exist - than your object is blurred. But if you can get rid of it, your object will be returned to the crystal sharp realm of 2d transformations. All you need to do is to copy 2d properties (x, y position and xscale, yscale) from 3d transformation matrix, remove the 3d transformation matrix, and apply those x, y, xscale, yscale to your object. The only backdraw of this method is that you can not use it on objects that needs z-axes related properties to display themselves correctly.</p>
<h3>Timers and fine tuning</h3>
<p>One thing we've noticed after the pattern was created is that timers we've used to control the timing of the rotations are performing somewhat strange if the HTML page containing the Flash embedded object looses focus. For some reason, when Flash page looses focus, background priority obviously doesn't have not enough memory for Flash timers to work correctly. Flash timers do not guarantee perfect timing anyway, but in the background window it will probably drop out of sync completely. So we needed some quick fix, to detect when the page containing our Flash is loosing focus. Again AS3 have come to the rescue, with it's External interface, and ability to easy communicate with JavaScript, that is, on the other hand capable of detecting when the page has lost the focus. <!-- Silverlight vs. Flash: How would you rate final patterns. --><br />
<!--<script src="http://www.good-survey.com/poll/e35aq46st30o.js" type="text/javascript"></script>--></p>
<p>View final comparison solution between <a title="Flash vs Silverlight - Superia pattern" href="http://labs.avivo.si/flash-vs-silverlight/" target="_blank"> Flash and Silverlight pattern</a>.</p>
<h2>Conclusion</h2>
<p> We found that with Flash we succeed to create pattern transformation as we wanted with smooth transitions and nice 3d effect. Working with Silverlight was very quick and we might even explore it further but we run out of time and beside that we where happy with Flash result. When looking closely you will see that when you embed Silverlight object and Flash object to HTML site, Silverlight need little more time to appears in browser than Flash and this is something we don't know the answer yet.</p>
<p>What have we learned:</p>
<ul>
<li>Flash has "dirty" history and uses bad mix of 'object' and 'embed' tags.</li>
<li>Flash cannot display HTML content reliably if plug-in is missing while Silverlight can do that easily. If plug-in is missing we just display static content.</li>
<li>Flash has native 3D support while Silverlight has no native support for 3D at the time. Silverlight has some experimental libraries which are heavily under development and not for production use.</li>
<li>Calculating 2D to look like 3D is overkill for developers. Too much effort, too small output. Use 3D engine for serious 3D development.</li>
</ul>
<p>Share your thoughts in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/12/flash-vs-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The service cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.</title>
		<link>http://tech.avivo.si/2010/11/the-service-cannot-be-activated-due-to-an-exception-during-compilation-the-exception-message-is-this-collection-already-contains-an-address-with-scheme-http-there-can-be-at-most-one-address-per-sch/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-service-cannot-be-activated-due-to-an-exception-during-compilation-the-exception-message-is-this-collection-already-contains-an-address-with-scheme-http-there-can-be-at-most-one-address-per-sch</link>
		<comments>http://tech.avivo.si/2010/11/the-service-cannot-be-activated-due-to-an-exception-during-compilation-the-exception-message-is-this-collection-already-contains-an-address-with-scheme-http-there-can-be-at-most-one-address-per-sch/#comments</comments>
		<pubDate>Thu, 25 Nov 2010 14:38:51 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[The service cannot be activated due to an exception during compilation]]></category>
		<category><![CDATA[There can be at most one address per scheme in this collection]]></category>
		<category><![CDATA[This collection already contains an address with scheme http]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[wcf service error]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=825</guid>
		<description><![CDATA[You can solve this issue by adding the following code to your web.config: &#60;system.serviceModel&#62; ... &#60;serviceHostingEnvironment&#62; &#60;baseAddressPrefixFilters&#62; &#60;add prefix="http://sample.domain.tld/Sample/"/&#62; &#60;/baseAddressPrefixFilters&#62; &#60;/serviceHostingEnvironment&#62; ... &#60;/system.serviceModel&#62;]]></description>
			<content:encoded><![CDATA[<p>You can solve this issue by adding the following code to your web.config: </p>
<pre class=xml>
&lt;system.serviceModel&gt;
	...
	&lt;serviceHostingEnvironment&gt;
	  &lt;baseAddressPrefixFilters&gt;
	  	&lt;add prefix="http://sample.domain.tld/Sample/"/&gt;
	  &lt;/baseAddressPrefixFilters&gt;
	&lt;/serviceHostingEnvironment&gt;
	...
&lt;/system.serviceModel&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/11/the-service-cannot-be-activated-due-to-an-exception-during-compilation-the-exception-message-is-this-collection-already-contains-an-address-with-scheme-http-there-can-be-at-most-one-address-per-sch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three essential plugins for Expression Blend</title>
		<link>http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=three-essential-plugins-for-expression-blend</link>
		<comments>http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 09:49:00 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=529</guid>
		<description><![CDATA[When it comes to vector graphics in Windows applications XAML is the most advanced format to choose from. XAML is great because developer/designer has full control over the graphics. Hidden reference lines, or garbage shapes, or objects can be relatively easily detected and removed from the code as compared to those formats that entirely rely [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to vector graphics in Windows applications <a title="Extensible application markup language" href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language">XAML</a> is the most advanced format to choose from. XAML is great because developer/designer has full control over the graphics. Hidden reference lines, or garbage shapes, or objects can be relatively easily detected and removed from the code as compared to those formats that entirely rely on GUI editor.</p>
<p>A XAML document can be created with plain Notepad but there are great apps like Visual Studio, Expression Blend and Kaxaml that simplify editing. What is missing in those apps is lack of XAML exporting support, like saving .xaml to .png file. Luckily there are plugins to do just that.</p>
<p><strong><a title="Expression Blend Printing Add-in" href="http://xbprint.codeplex.com/">xbprint</a> </strong>is printing <strong>plugin </strong>for <strong>Expression Blend</strong> 3 hosted on CodePlex. Installation of the utility must be perfomed manually by extracting files to the Addins folder in Expression Blend directory. But once the plugin is installed it is easy to use. Set margins, alignment, paper size and click Print.</p>
<p><a rel="attachment wp-att-531" href="http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/xbprint_medium/"><img class="alignnone size-medium wp-image-531" title="xbprint screenshot" src="http://tech.avivo.si/wp-content/uploads/2010/07/xbprint_medium-600x375.jpg" alt="xbprint screenshot" width="600" height="375" /></a></p>
<p><strong><a title="Expression Blend Rasterizer Add-in" href="http://xbraster.codeplex.com/">xbraster</a> </strong>is <strong>xaml to raster image</strong> converting plugin, a close relative to xbprint. Installation and use is similar. xbraster can convert XAML to PNG, JPEG, TIFF, GIF or bitmap.</p>
<p><a rel="attachment wp-att-532" href="http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/xbraster_medium/"><img class="alignnone size-medium wp-image-532" title="xbraster screenshot" src="http://tech.avivo.si/wp-content/uploads/2010/07/xbraster_medium-600x375.jpg" alt="xbraster screenshot" width="600" height="375" /></a></p>
<p><a title="Sprite Generator Add-in for Expression Blend" href="http://xbsprite.codeplex.com"><strong>xbsprite</strong></a> is a <strong>sprite image generating</strong> plugin. Input xaml files are rasterized and combined in one image with optional CSS and HTML output for use on a web page.</p>
<p><a rel="attachment wp-att-535" href="http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/xbsprite_medium/"><img class="alignnone size-medium wp-image-535" title="xbsprite screenshot" src="http://tech.avivo.si/wp-content/uploads/2010/07/xbsprite_medium-600x375.jpg" alt="xbsprite screenshot" width="600" height="375" /></a></p>
<p>For advanced and professional use of XAML xbprint, xbraster and xbsprite are must-have plugins.</p>
<p><strong>EDIT: xbprint, xbraster and xbsprite can run directly from desktop &#8211; no need to have<br />
Expression Blend installed.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2010/07/three-essential-plugins-for-expression-blend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WriteableBitmap does not Render()?!</title>
		<link>http://tech.avivo.si/2009/12/writeablebitmap-does-not-render/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=writeablebitmap-does-not-render</link>
		<comments>http://tech.avivo.si/2009/12/writeablebitmap-does-not-render/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 16:36:32 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Warnings]]></category>
		<category><![CDATA[capture]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[not]]></category>
		<category><![CDATA[raster]]></category>
		<category><![CDATA[Render]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[vector]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[WriteableBitmap]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=223</guid>
		<description><![CDATA[We spent quite some time working on a Silverlight deep zoom application. Like in other projects, a problem appears sooner or later. This time with the WriteableBitmap that couldn&#8217;t take screenshot of a basic shape. //Simple ellipse (green circle) Ellipse element = new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Colors.Green) [...]]]></description>
			<content:encoded><![CDATA[<p>We spent quite some time working on a Silverlight deep zoom application. Like in other projects, a problem appears sooner or later. This time with the <strong>WriteableBitmap</strong> that couldn&#8217;t take screenshot of a basic shape.</p>
<pre class="c-sharp">//Simple ellipse (green circle)
Ellipse element = new Ellipse()
{
	Width = 50,
	Height = 50,
	Fill = new SolidColorBrush(Colors.Green)
};

//WriteableBitmap current = new WriteableBitmap(50, 50);
//current.Render(element, new MatrixTransform()); //DOES NOT WORK!!! - renders blank transparent image

//But with the constructor works fine
WriteableBitmap bitmap = new WriteableBitmap(element, new MatrixTransform());

//Ellipse captured as raster image painted on a panel's background
Grid grid = new Grid()
{
	Width = 50,
	Height = 50,
	Background = new ImageBrush() { ImageSource = bitmap }
};</pre>
<p>Summary for the Render() method says: <em>&#8220;Renders an element within the bitmap.&#8221;</em><br />
<strong>Render()</strong> method didn&#8217;t output required result but <strong>using constructor instead</strong> of the method did do the job. Input parameters were the same.</p>
<p>Maybe Render() method do something else, maybe it is a problem with Vista 64-bit&#8230;</p>
<p>Anyway, WriteableBitmap is very useful in Silverlight 3, luckily it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/12/writeablebitmap-does-not-render/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight: inherit a generic class from UserControl</title>
		<link>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silverlight-inherit-a-generic-class-from-usercontrol</link>
		<comments>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 17:57:49 +0000</pubDate>
		<dc:creator>developer</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[derive]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[inherit]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[UserControl]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://tech.avivo.si/?p=208</guid>
		<description><![CDATA[Note! This blog post is just an idea than well tested solution, more a review that detailed description. In Silverlight UserControl and Page classes are usually used with xaml. Root tags in xaml define the type, like so: xaml &#60;UserControl x:Class="MyView"&#62; ... &#60;/UserControl&#62; code-behind namespace MyNamespace { class MyView : UserControl } Sometimes, developers want [...]]]></description>
			<content:encoded><![CDATA[<p>Note! This blog post is just an idea than well tested solution, more a review that detailed description.<br />
In Silverlight UserControl and Page classes are usually used with xaml. Root tags in xaml define the type, like so:</p>
<pre class="c-sharp">xaml
&lt;UserControl x:Class="MyView"&gt;
...
&lt;/UserControl&gt;

code-behind
namespace MyNamespace
{
  class MyView : UserControl
}</pre>
<p>Sometimes, developers want to extend UserControl, i.e. as View by MVVM pattern.</p>
<pre class="c-sharp">xaml
&lt;v:ViewBase x:Class="MyNamespace.MyView" xmlns:v="clr-namespace:MyNamespace"&gt;
...
&lt;/v:ViewBase&gt;

code-behind
namespace MyNamespace
{
  class MyView : ViewBase /* ViewBase is a custom class */
}</pre>
<p>Step further, every View should have it&#8217;s specialized model (ViewModel), thus base class could integrate a Model property. To avoid casting one should use generics, like ViewBase&lt;MyViewModel&gt;.</p>
<pre class="c-sharp">xaml
&lt;!-- There's a problem, generics cannot be written in xaml. --&gt;

code-behind
namespace MyNamespace
{
  class MyView : ViewBase&lt;MyViewModel&gt; /* ViewBase is a custom class */
}</pre>
<p>Generics cannot be written directly in xaml? There is a workaround:<br />
1. Use a wrapper, described <a href="http://www.lab101.be/2008/07/silverlight-usercontrol-inheritance/">here</a><br />
2. Create a new non-generic class, like in this sample:</p>
<pre class="c-sharp">xaml
&lt;v:MyViewBase x:Class="MyNamespace.MyView" xmlns:v="clr-namespace:MyNamespace"&gt;
...
&lt;/v:MyViewBase&gt;

code-behind
namespace MyNamespace
{
  class MyView : MyViewBase
}

public abstract class MyViewBase : ViewBase&lt;MyViewModel&gt;
{
  /* non-generic class */
}</pre>
<p><strong>Appendix: ViewBase&lt;TViewModel&gt; class</strong></p>
<pre class="c-sharp">public abstract class ViewBase&lt;TViewModel&gt; : UserControl, INotifyPropertyChanged where TViewModel : ViewModelBase, new()
{
	private TViewModel model;
	public TViewModel Model
	{
		get
		{
			if (this.model == null)
			{
				this.model = new TViewModel();
				base.DataContext = this.model;
			}
			return this.model;
		}
		set
		{
			if (this.model != value)
			{
				this.model = value;
				base.DataContext = this.model;
				OnPropertyChanged("Model");
			}
		}
	}
}</pre>
<p>References:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/400778/usercontrol-that-has-a-generic-class-in-its-inheritance-tree">StackOverflow: UserControl that has a generic class in its inheritance tree</a></li>
<li><a href="http://stackoverflow.com/questions/225878/how-to-correctly-inherit-from-a-usercontrol-defined-in-xaml-in-silverlight">StackOverflow: How to correctly inherit from a UserControl defined in xaml in Silverlight</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/11/silverlight-inherit-a-generic-class-from-usercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to focus window in WPF when it gets out of focus</title>
		<link>http://tech.avivo.si/2009/11/how-to-focus-window-in-wpf-when-it-gets-out-of-focus/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-focus-window-in-wpf-when-it-gets-out-of-focus</link>
		<comments>http://tech.avivo.si/2009/11/how-to-focus-window-in-wpf-when-it-gets-out-of-focus/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 10:48:01 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[bring to front]]></category>
		<category><![CDATA[interop]]></category>
		<category><![CDATA[maximize]]></category>
		<category><![CDATA[ufocused]]></category>
		<category><![CDATA[window focus]]></category>
		<category><![CDATA[windows forms woundation]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://blog.sweetucan.com/?p=190</guid>
		<description><![CDATA[Sometimes you want to have your WPF application in &#8220;kiosk&#8221; mode (fullscreen) and you can do this with this code: Window w = new Window(); w.WindowStyle = WindowStyle.None; w.WindowState = WindowState.Maximized; w.TopMost = true; w.ResizeMode=NoResize; w.Show(); But, some system message (yellow balloon in system tray shows Taskbar in focus or any other Window system task) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to have your WPF application in &#8220;kiosk&#8221; mode (fullscreen) and you can do this with this code:</p>
<pre class="c-sharp">Window w = new Window();
w.WindowStyle = WindowStyle.None;
w.WindowState = WindowState.Maximized;
w.TopMost = true;
w.ResizeMode=NoResize;
w.Show();</pre>
<p>But, some system message (yellow balloon in system tray shows Taskbar in focus or any other Window system task) can get your application out of focus. In order to get it back to focus use this code:</p>
<pre class="c-sharp">//Interop.cs
using System.Runtime.InteropServices;
using System.Windows.Interop;

public class Interop
{
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();

public static IntPtr GetWindowHandle(Window window)
{
return new WindowInteropHelper(window).Handle;
}
}

//Somewhere in main window
IntPtr window = Interop.GetWindowHandle(this);
IntPtr focused = Interop.GetForegroundWindow();
if (window != focused)
{
Interop.SetForegroundWindow(window);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/11/how-to-focus-window-in-wpf-when-it-gets-out-of-focus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 2.0 &#8211; Invoke method with Reflection</title>
		<link>http://tech.avivo.si/2009/07/silverlight-20-invoke-method-with-reflection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=silverlight-20-invoke-method-with-reflection</link>
		<comments>http://tech.avivo.si/2009/07/silverlight-20-invoke-method-with-reflection/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 13:45:39 +0000</pubDate>
		<dc:creator>Avivo</dc:creator>
				<category><![CDATA[Programming Techniques]]></category>
		<category><![CDATA[Silverlight/WPF]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[invoke]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[run-time]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://blog.sweetucan.com/?p=123</guid>
		<description><![CDATA[When deciding whether to create a rich graphical web application with lots of animations either with Silverlight or ASP .NET, Silverlight definitely wins. But when deciding whether put a database in first place then server side scripts (i.e. ASP .NET) have the advantage. Anyway, if you are accessing database from Silverlight you&#8217;ve probably came across [...]]]></description>
			<content:encoded><![CDATA[<p>When deciding whether to create a rich graphical web application with lots of animations either with Silverlight or ASP .NET, Silverlight definitely wins. But when deciding whether put a database in first place then server side scripts (i.e. ASP .NET) have the advantage.</p>
<p>Anyway, if you are <strong>accessing database from Silverlight</strong> you&#8217;ve probably came across WCF or other  web services. Let&#8217;s say you have <strong>100 tables</strong> and want to use <strong>WCF</strong>. Each table has <strong>Select</strong>, <strong>Insert</strong>, <strong>Update </strong>and <strong>Delete </strong>methods generated like <strong>InsertUser(User item)</strong>. Visual Studio 2008 can automatically generated WCF proxy classes in Silverlight which are asynchronous. Suddenly, handling application logic and database becomes complex for development.</p>
<p>Those methods have <strong>similarities </strong>- Select, Insert, Update and Delete are repeated but for <strong>different table names</strong>. Idea is to use <strong>System.Reflection</strong> to simply and minimize development time. What the Reflection classes do is they use run time variables (i.e. string, int, etc.) to dynamically invoke methods according to situation in run time (cannot be determined in design time while developing).</p>
<p>Let&#8217;s say you have a method <strong>InsertCustomer(Customer item) in WCF</strong> and Visual Studio generates <strong>InsertCustomerAsync(Customer item) for Silverlight</strong>. Application can generate &#8220;InsertCustomerAsync&#8221; as string on demand. Then a method invoke by string is needed:</p>
<blockquote><p>using System.Reflection;</p>
<p>&#8230;</p>
<p>//MyWebService is WCF proxy class and Customer is data entity</p>
<p>MethodInfo methodInfo = typeof(MyWebService).GetMethod(&#8220;InsertCustomerAsync&#8221;, new Type[] { typeof(Customer) });</p>
<p>methodInfo.Invoke(con, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this.item, }, null);</p></blockquote>
<p>Then a &#8220;completed&#8221; event needs to be caught:</p>
<blockquote><p>MethodInfo handlerInfo = typeof(ReflectionDemo&lt;T&gt;).GetMethod(&#8220;SaveHandler&#8221;, BindingFlags.NonPublic | BindingFlags.Instance);<br />
EventInfo eventInfo = typeof(MyWebService).GetEvent(eventName);<br />
eventInfo.AddEventHandler(con, Delegate.CreateDelegate(eventInfo.EventHandlerType, this, handlerInfo));</p></blockquote>
<p>Putting all code together:</p>
<blockquote><p>public class ReflectionDemo&lt;T&gt; where T : new()<br />
{<br />
private T item;</p>
<p>public bool IsUpdate<br />
{<br />
get;<br />
set;<br />
}</p>
<p>public void Save()<br />
{<br />
try<br />
{<br />
if (this.item != null)<br />
{<br />
//Get names<br />
string methodName = (this.IsUpdate ? &#8220;Update&#8221; : &#8220;Insert&#8221;) + typeof(T).Name + &#8220;Async&#8221;; //e.g. UpdateCustomerAsync<br />
string eventName = (this.IsUpdate ? &#8220;Update&#8221; : &#8220;Insert&#8221;) + typeof(T).Name + &#8220;Completed&#8221;; //e.g. UpdateCustomerCompleted<br />
string eventArgsName = (this.IsUpdate ? &#8220;Update&#8221; : &#8220;Insert&#8221;) + typeof(T).Name + &#8220;CompletedEventArgs&#8221;; //e.g. UpdateCustomerCompletedEventArgs</p>
<p>//Create a connection<br />
MyWebService con = new MyWebService();</p>
<p>//Attach an event handler in run time retrieved event (e.g. something like &#8220;con.UpdateCustomerCompleted += &#8230;&#8221; at design time)<br />
MethodInfo handlerInfo = typeof(ReflectionDemo&lt;T&gt;).GetMethod(&#8220;SaveHandler&#8221;, BindingFlags.NonPublic | BindingFlags.Instance);<br />
EventInfo eventInfo = typeof(MyWebService).GetEvent(eventName);<br />
eventInfo.AddEventHandler(con, Delegate.CreateDelegate(eventInfo.EventHandlerType, this, handlerInfo));</p>
<p>//Invoke method in run time (e.g. something like &#8220;con.UpdateCustomerAsync(this.item);&#8221; at design time)<br />
MethodInfo methodInfo = typeof(MyWebService).GetMethod(methodName, new Type[] { typeof(T) }); //From overloaded methods get the one with single parameter<br />
methodInfo.Invoke(con, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this.item, }, null); //Invoke the method immediately<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
//Exception may be thrown in various situations (e.g. method cannot be found)<br />
//Insert breakpoint here while debugging<br />
}<br />
}</p>
<p>protected void SaveHandler(object sender, EventArgs args)<br />
{</p>
<p>//Handle event logic here<br />
//Sample how to cast to a derived EventArgs with known properties:</p>
<p>Type type = args.GetType();<br />
Exception ex = type.GetProperty(&#8220;Error&#8221;).GetValue(args, null) as Exception ?? null;<br />
Customer item = (Customer)type.GetProperty(&#8220;Customer&#8221;).GetValue(args, null);<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://tech.avivo.si/2009/07/silverlight-20-invoke-method-with-reflection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

