<?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>Chui&#039;s Counterpoint</title>
	<atom:link href="http://www.redmountainsw.com/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redmountainsw.com/wordpress</link>
	<description>Just another Red Mountain Software Sites site</description>
	<lastBuildDate>Thu, 02 Feb 2012 00:53:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>RunOnUiThread Macro</title>
		<link>http://www.redmountainsw.com/wordpress/2012/02/02/runonuithread-macro/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/02/02/runonuithread-macro/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 00:53:37 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[scheme]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1397</guid>
		<description><![CDATA[My first Scheme macro! (define-syntax run-ui (syntax-rules () ((run-ui activity body ...) (android.app.Activity:runOnUiThread activity (runnable (lambda () body ... )))))) To test the macro (from Kawa) (require &#039;syntax-utils) (display (expand &#039;(run-ui *activity* (android.util.Log:v &#34;kawa-hello&#34; &#34;test log&#34;) ((Toast:makeText *activity* &#34;Good Morning Australia&#34; Toast:LENGTH_LONG):show)))) To run it: java -jar kawa-1.11.jar -f test.scm Note: don&#8217;t do this, java [...]]]></description>
			<content:encoded><![CDATA[<p>My first Scheme macro!</p>
<pre class="brush: php">

 (define-syntax run-ui
  (syntax-rules ()
   ((run-ui activity body ...)
    (android.app.Activity:runOnUiThread activity
     (runnable
      (lambda ()
        body ... ))))))
</pre>
<p>To test the macro (from Kawa)</p>
<pre class="brush: php">

(require &#039;syntax-utils)
(display (expand
 &#039;(run-ui *activity*
   (android.util.Log:v &quot;kawa-hello&quot; &quot;test log&quot;)
    ((Toast:makeText *activity* &quot;Good Morning Australia&quot; Toast:LENGTH_LONG):show))))
</pre>
<p>To run it:</p>
<pre class="brush: php">

java -jar kawa-1.11.jar -f test.scm
</pre>
<p><strong>Note: don&#8217;t do this, </strong></p>
<pre class="brush: php">

java -jar kawa-1.11.jar test.scm 
</pre>
<p>as <strong>expand</strong> mysteriously doesn&#8217;t expand.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/02/02/runonuithread-macro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kawa scheme and event handlers</title>
		<link>http://www.redmountainsw.com/wordpress/2012/02/01/kawa-scheme-and-event-handlers/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/02/01/kawa-scheme-and-event-handlers/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 02:44:18 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1395</guid>
		<description><![CDATA[Kawa makes writing eventhandlers rather easy by providing a short hand for creating anonymous classes from lambdas. Reference An anonymous class is commonly used in the Java platform where a function language would use a lambda expression. Examples are call-back handlers, events handlers, and run methods. In these cases Kawa lets you use a lambda [...]]]></description>
			<content:encoded><![CDATA[<p>Kawa makes writing eventhandlers rather easy by providing a short hand for creating anonymous classes from lambdas.</p>
<p><a href="http://www.gnu.org/software/kawa/Anonymous-classes.html#Lambda-as-shorthand-for-anonymous-class">Reference</a></p>
<p>An anonymous class is commonly used in the Java platform where a function language would use a lambda expression. Examples are call-back handlers, events handlers, and run methods. In these cases Kawa lets you use a lambda expression as a short-hand for an anonymous class. For example:</p>
<pre class="brush: php">

(button:addActionListener
  (lambda (e) (do-something)))
</pre>
<p>is equivalent to:</p>
<pre class="brush: php">

(button:addActionListener
  (object (java.awt.event.ActionListener)
    ((actionPerformed (e ::java.awt.event.ActionEvent))::void
     (do-something))))
</pre>
<p>The magic starts at <code>gnu/kawa/reflect/CompileBuildObject.java</code>, where findMember looks up a setXXXX or addXXXX member on a class. Next, buildSetter calls CompileReflect.makeSetterCall&#8230;. (I haven&#8217;t traced through)&#8230; that calls gnu/expr/InlineCalls.java that examines for SAM <code>checkSingleAbstractMethod</code>, and that creates a new anonymous class (new ObjectExp) ?</p>
<p>However, on Android, Kawa is unable to create new classes on the fly. Instead, we need to create a proxy and a custom InvocationHandler that calls our lambdas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/02/01/kawa-scheme-and-event-handlers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing Network Interfaces on Android with Kawa</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/29/listing-network-interfaces-on-android-with-kawa/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/29/listing-network-interfaces-on-android-with-kawa/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 10:51:52 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[scheme]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1388</guid>
		<description><![CDATA[The following works for me: (define (Enumeration-&#38;amp;amp;amp;amp;gt;list (enum :: java.util.Enumeration)) :: list (let loop ((ls &#039;())) (if (enum:hasMoreElements) (loop (cons (enum:nextElement) ls)) (reverse ls)))) (require &#039;srfi-1) (define (enumerate-network-interfaces) (map (lambda (x :: java.net.InetAddress) x:host-address) (filter (lambda (x :: java.net.InetAddress) (not (x:is-loopback-address))) (concatenate (map (lambda (x :: java.net.NetworkInterface) (Enumeration-&#38;amp;amp;amp;amp;gt;list x:inet-addresses)) (Enumeration-&#38;amp;amp;amp;amp;gt;list java.net.NetworkInterface:network-interfaces)))))) &#8230; which is the [...]]]></description>
			<content:encoded><![CDATA[<p><script src="https://raw.github.com/magnusvw/hollywoodr/master/hollywoodr.min.js"></script></p>
<p>The following works for me:</p>
<pre class="brush: php">

(define (Enumeration-&amp;amp;amp;amp;amp;gt;list (enum :: java.util.Enumeration)) :: list
  (let loop ((ls &#039;()))
    (if (enum:hasMoreElements)
      (loop (cons (enum:nextElement) ls))
      (reverse ls))))

(require &#039;srfi-1)
(define (enumerate-network-interfaces)
 (map (lambda (x :: java.net.InetAddress) x:host-address)
  (filter (lambda (x :: java.net.InetAddress) (not (x:is-loopback-address)))
    (concatenate
       (map (lambda (x :: java.net.NetworkInterface) (Enumeration-&amp;amp;amp;amp;amp;gt;list x:inet-addresses))
         (Enumeration-&amp;amp;amp;amp;amp;gt;list java.net.NetworkInterface:network-interfaces))))))
</pre>
<p>&#8230; which is the functional equivalent of the following in Java</p>
<pre class="brush: java">

    for (Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
	            NetworkInterface intf = en.nextElement();
	            for (Enumeration&lt;InetAddress&gt; enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
	                InetAddress inetAddress = enumIpAddr.nextElement();
	                if (!inetAddress.isLoopbackAddress()) {
	                    return inetAddress.getHostAddress().toString();
	                }
	            }
	        }
</pre>
<p>Unfortunately, the Scheme version isn&#8217;t much more readable than the Java one.</p>
<p>Here&#8217;s another version in Scheme, using <code>named let</code>.</p>
<pre class="brush: php">
(let loop ((interfaces :: java.util.Enumeration[java.net.NetworkInterface] java.net.NetworkInterface:network-interfaces))
   (if (interfaces:has-more-elements)
       (let ((interface (interfaces:next-element)))
         (if (not (interface:is-up))
             (loop interfaces))
         (if (interface:is-virtual)
             (loop interfaces))
         (display interface:display-name) (newline)
         (let loop ((inet-addresses :: java.util.Enumeration[java.net.InetAddress] interface:inet-addresses))
             (if (inet-addresses:has-more-elements)
                 (let ((inet-address (inet-addresses:next-element)))
                      (display &amp;quot;--&amp;quot;)
                      (display inet-address:host-address)
                      (newline))
                 (loop inet-addresses)))
         (loop interfaces))))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/29/listing-network-interfaces-on-android-with-kawa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheme REPL on Android Experiments</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/28/scheme-repl-on-android-experiments/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/28/scheme-repl-on-android-experiments/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 22:44:22 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1381</guid>
		<description><![CDATA[My first attempt of running Scheme on Android weren&#8217;t very good, and Helmut Eller provided a nicer implementation of REPL which I reproduce here: (define-syntax try-with-resources (syntax-rules () ((try-with-resources () body ...) (begin body ...)) ((try-with-resources ((var val) (vars vals) ...) body ...) (let ((var val)) (try-finally (try-with-resources ((vars vals) ...) body ...) (invoke var [...]]]></description>
			<content:encoded><![CDATA[<p>My first attempt of running Scheme on Android weren&#8217;t very good, and Helmut Eller provided a nicer implementation of REPL which I reproduce here:</p>
<pre class="brush: php">

(define-syntax try-with-resources
  (syntax-rules ()
    ((try-with-resources () body ...)
     (begin body ...))
    ((try-with-resources ((var val) (vars vals) ...) body ...)
     (let ((var val))
       (try-finally
        (try-with-resources ((vars vals) ...) body ...)
        (invoke var &#039;close)))))) 

(define (msg (fstring string) #!rest args)
  (android.util.Log:v &quot;kawa-hello&quot; (apply format fstring args))) 

(define (start-telnet-repl (socket java.net.Socket))
  (let ((lang (gnu.expr.Language:getDefaultLanguage)))
    (msg &amp;amp;amp;quot;starting telnet repl ~a ~a&amp;amp;amp;quot; socket lang)
    (kawa.TelnetRepl:serve lang socket))) 

(define (start-repl port)
  (try-with-resources ((server (java.net.ServerSocket port)))
   (let loop ()
     (msg &amp;amp;amp;quot;listing on ~a (~a)&amp;amp;amp;quot; port server)
     (let ((socket (server:accept)))
       (msg &amp;amp;amp;quot;connected ~a &amp;amp;amp;quot; socket)
       (start-telnet-repl socket)
       (loop))))) 

(define-variable *activity* #f) 

(define (init-kawa activity)
  (kawa.standard.Scheme:registerEnvironment)
  (set! gnu.expr.ModuleExp:compilerAvailable #f)
  (set! gnu.expr.ModuleExp:alwaysCompile #f)
  (set! *activity* activity)
  (future (start-repl 4444))) 

(define-simple-class hello (android.app.Activity)
  ((onCreate saved-state ::android.os.Bundle) ::void
   (let ((self (this)))
     (invoke-special android.app.Activity self &#039;onCreate saved-state)
     (init-kawa self)
     (self:setContentView
      (android.widget.TextView
       self
       text: &amp;amp;amp;quot;Hello, Android from Kawa Scheme!&amp;amp;amp;quot;)))))
</pre>
<p>The good news with this implementation is now I can reconnect to telnet multiple times, and the *activity* global variable is defined, which allows me to do this from REPL.</p>
<pre class="brush: php">

#|kawa:76|# (*activity*:run-on-ui-thread
             (runnable
               (lambda ()
                 ((android.widget.Toast:makeText
                     *activity*
                     &quot;Hello from REPL&quot;
                     android.widget.Toast:LENGTH_LONG):show))
</pre>
<p>Here&#8217;s one where we change the UI on the fly from the REPL</p>
<pre class="brush: php">

#|kawa:78|#
(*activity*:runOnUiThread
  (runnable
     (lambda ()
        (*activity*:setContentView
          (android.widget.TextView *activity* text: &quot;Changed Content&quot;)))))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/28/scheme-repl-on-android-experiments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheme REPL on Android Part 1</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/23/scheme-repl-on-android-part-1/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/23/scheme-repl-on-android-part-1/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 23:10:01 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1371</guid>
		<description><![CDATA[These are not instructions. These are rather my notes on what I had to do to get a remote Scheme REPL running on Android. Patch Kawa Use default classloader instead of the android specific one. There are preprocessors involved, so the only way is to modify ifdef Android to ifdef xxAndroid. /* #ifdef JAVA2 */ [...]]]></description>
			<content:encoded><![CDATA[<p>These are not instructions. These are rather my notes on what I had to do to get a remote Scheme REPL running on Android.</p>
<h2>Patch Kawa</h2>
<p>Use default classloader instead of the android specific one. There are preprocessors involved, so the only way is to modify <code>ifdef Android</code> to <code>ifdef xxAndroid</code>.</p>
<pre class="brush: java">
  /* #ifdef JAVA2 */
  public static ClassLoader getContextClassLoader ()
  {
    try
      {
        /* #ifdef xxAndroid */
        //return ClassLoader.getSystemClassLoader();
        /* #else */
        return Thread.currentThread().getContextClassLoader();
        /* #endif */
      }
    catch (java.lang.SecurityException ex)
      {
        /* The .class syntax below also works for JDK 1.4, but it&#039;s just
           syntactic sugar, so there is no benefit in using it. */
        /* #ifdef JAVA5 */
        return ObjectType.class.getClassLoader();
        /* #else */
        // return thisClassLoader;
        /* #endif */
      }
  }
  /* #endif */
</pre>
<h2>Set up Scheme project</h2>
<p>Set up a <a href="http://per.bothner.com/blog/2010/AndroidHelloScheme/">Scheme-based Android project</a> as per Per Bothner&#8217;s instructions.</p>
<p>Source for repl.scm (don&#8217;t use hello.scm)</p>
<pre class="brush: php">

(module-static #t)

(module-compile-options
 warn-unknown-member: #t
 warn-undefined-variable: #t
 )

(require &#039;android-defs)

(define (msg (fstring string) #!rest args)
  (android.util.Log:v &amp;amp;amp;quot;kawa-hello&amp;amp;amp;quot; (apply format fstring args)))

(define (start-repl port)
  (begin
    ; required! otherwise the getLanguage() call will fail
    (kawa.standard.Scheme:registerEnvironment)
    ; required! as Android cannot compile to java
    (set! gnu.expr.ModuleExp:alwaysCompile #f)
    (let* ((server (java.net.ServerSocket port)))
      (msg &amp;amp;amp;quot;listing on ~a (~a)&amp;amp;amp;quot; port server)
      (let ((socket (server:accept)))
        (msg &amp;amp;amp;quot;connected ~a &amp;amp;amp;quot; socket)
        (let ((in (gnu.mapping.InPort (socket:getInputStream)))
              (out (gnu.mapping.OutPort (socket:getOutputStream))))
          (parameterize ((current-input-port in)
                         (current-output-port out))
            (do () (#f)
              (try-catch
               (begin
                 (format #t &amp;amp;amp;quot;\n&amp;amp;amp;gt; &amp;amp;amp;quot; )
                 (force-output)
                 (let ((form (read)))
                   (format #t &amp;amp;amp;quot;form: ~s\n&amp;amp;amp;quot; form)
                   (format #t &amp;amp;amp;quot;~s&amp;amp;amp;quot; (eval form (interaction-environment)))))
               (e java.lang.Exception
                  (e:printStackTrace out))))))))))

(activity hello
  (on-create-view
    (begin
      (java.lang.Thread:run (java.lang.Thread:new (runnable (start-repl 4444))))
      (android.widget.TextView (this)
         text: &amp;amp;amp;quot;Hello, Android REPL from Kawa Scheme!&amp;amp;amp;quot;))))
</pre>
<h2>Modify the start up file</h2>
<p>In build.xml</p>
<pre class="brush: xml">
   &lt;arg value=&quot;-C&quot;/&gt;
   &lt;arg file=&quot;src/kawa/android/repl.scm&quot;/&gt;
</pre>
<h2>Deploy</h2>
<p>Deploy and view the logs</p>
<p><code>ant debug; adb uninstall kawa.android; adb install bin/KawaHello-debug.apk; adb logcat</code></p>
<h2>Test</h2>
<pre class="brush: php">
; Do this if you are running on physical hardware
adb forward tcp:4444 tcp:4444

telnet localhost 4444
(+ 1 1)
</pre>
<h2>Still to be resolved</h2>
<ul>
<li>Text label doesn&#8217;t show up</li>
<li>Compiling classes and libraries quite slow, why is it being repeated?</li>
<li>Start repl after showing text label?</li>
<li>How do I make UI calls back on the main thread?</li>
</ul>
<h2>Troubleshooting</h2>
<h3>unable to resolve static field 9 (Lit0)</h3>
<p>Rename your scheme file from hello.scm to hello2.scm as there is a name-clash &#8211; I&#8217;m not sure why yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/23/scheme-repl-on-android-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running clojurescript from Cygwin</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/20/running-clojurescript-from-cygwin/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/20/running-clojurescript-from-cygwin/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 21:11:52 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1369</guid>
		<description><![CDATA[Troubleshooting guide. These tells you what the script is trying to do. bash -x script/deps bash -x script/run Here&#8217;s mine once cleaned up. I used java.ext.dirs as I don&#8217;t think wildcards on classpath worked. $ java -server -cp &#039;lib;lib/dev;lib/clojurescript/src/clj;lib/clojurescript/src/cljs;lib/clojurescript/test/cljs;lib/do mina/src/cljs;src/app/clj;src/app/cljs;src/app/cljs-macros;src/lib/clj;src/lib/cljs;test;templates&#039; &#039;-Djava.ext.dirs=li b;lib/dev;lib/clojurescript/src/clj;lib/clojurescript/src/cljs;lib/clojurescript/test/cljs;lib/domina/src/cljs;src/app/ clj;src/app/cljs;src/app/cljs-macros;src/lib/clj;src/lib/cljs;test;templates&#039; jline.ConsoleRunner clojure.main -e &#039;(use &#039;\&#039;&#039;one.sample.dev-server) (run-server) (println &#34;The application is being served [...]]]></description>
			<content:encoded><![CDATA[<p>Troubleshooting guide.</p>
<p>These tells you what the script is trying to do.</p>
<pre class="brush: php">
bash -x script/deps
bash -x script/run
</pre>
<p>Here&#8217;s mine once cleaned up. I used java.ext.dirs as I don&#8217;t think wildcards on classpath worked.</p>
<pre class="brush: sh">
$ java -server -cp &#039;lib;lib/dev;lib/clojurescript/src/clj;lib/clojurescript/src/cljs;lib/clojurescript/test/cljs;lib/do
mina/src/cljs;src/app/clj;src/app/cljs;src/app/cljs-macros;src/lib/clj;src/lib/cljs;test;templates&#039; &#039;-Djava.ext.dirs=li
b;lib/dev;lib/clojurescript/src/clj;lib/clojurescript/src/cljs;lib/clojurescript/test/cljs;lib/domina/src/cljs;src/app/
clj;src/app/cljs;src/app/cljs-macros;src/lib/clj;src/lib/cljs;test;templates&#039; jline.ConsoleRunner clojure.main -e &#039;(use
 &#039;\&#039;&#039;one.sample.dev-server)
 (run-server)
 (println &quot;The application is being served from localhost:8080&quot;)&#039; --repl
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/20/running-clojurescript-from-cygwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A nicer way to handle dependent values on PropertyChanged</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/17/a-nicer-way-to-handle-dependent-values-on-propertychanged/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/17/a-nicer-way-to-handle-dependent-values-on-propertychanged/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 07:44:44 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1365</guid>
		<description><![CDATA[Here&#8217;s a contrived example of how PropertyChanged can get difficult. The property Total depends on Values A and B, and if any of them change, Total has to be read again. public int Total { get { return A + B; } } public int A { get { return m_A; } set { m_A [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a contrived example of how PropertyChanged can get difficult. The property Total depends on Values A and B, and if any of them change, Total has to be read again. </p>
<pre class="brush: c#">
public int Total
{
  get { return A + B; }
}

public int A
{
  get { return m_A; }
  set { m_A = value; RaisePropertyChanged(&quot;A&quot;); RaisePropertyChanged(&quot;Total&quot;); }
}

public int B
{
  get { return m_B: }
  set { m_B = value; RaisePropertyChanged(&quot;B&quot;); RaisePropertyChanged(&quot;Total&quot;); }
}
</pre>
<p>We can solve this by using a helper attribute, so that the new code looks like this. Notice the increased clarity and ease of adding more dependent variables:</p>
<pre class="brush: c#">

[DependsOn(&quot;A&quot;)]
[DependsOn(&quot;B&quot;)]
public int Total
{
  get { return A + B; }
}

public int A
{
  get { return m_A; }
  set { m_A = value; RaisePropertyChanged(&quot;A&quot;); }
}

public int B
{
  get { return m_B: }
  set { m_B = value; RaisePropertyChanged(&quot;B&quot;); }
}
</pre>
<p>Here&#8217;s the supporting code</p>
<pre class="brush: c#">
        internal Dictionary&lt;string, IEnumerable&lt;string&gt;&gt; m_DependentAttributes = new Dictionary&lt;string, IEnumerable&lt;string&gt;&gt;();
        private void SetupDependentAttributes()
        {
            foreach (var property in this.GetType().GetProperties())
            {
                string propertyName = property.Name;

                DependsOnAttribute[] attrs = (DependsOnAttribute[])property.GetCustomAttributes(typeof(DependsOnAttribute), true);
                foreach (var dependOnAttr in attrs)
                {
                    foreach (string dependsOnPropertyName in dependOnAttr.DependsOnPropertyNames)
                    {
                        if (!m_DependentAttributes.ContainsKey(dependsOnPropertyName))
                            m_DependentAttributes[dependsOnPropertyName] = new List&lt;string&gt;();
                        (m_DependentAttributes[dependsOnPropertyName] as List&lt;string&gt;).Add(propertyName);
                    }
                }

                // If a property is ObservableCollection, then CollectionChanged should also raise PropertyChanged.
                object obs = property.GetGetMethod().Invoke(this, null);
                if (obs != null &amp;&amp; obs is System.Collections.Specialized.INotifyCollectionChanged)
                {
                    EventInfo collectionChanged = obs.GetType().GetEvent(&quot;CollectionChanged&quot;);
                    if (collectionChanged != null)
                    {
                        (obs as System.Collections.Specialized.INotifyCollectionChanged).CollectionChanged +=
                            (s, e) =&gt; { RaisePropertyChanged(propertyName); };
                    }
                }
            }
        }

        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                if (m_DependentAttributes.ContainsKey(propertyName))
                    foreach (var dependentPropertyName in m_DependentAttributes[propertyName])
                    {
                        RaisePropertyChanged(dependentPropertyName);
                    }
            }
        }

    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
    sealed class DependsOnAttribute : Attribute
    {
        // See the attribute guidelines at
        //  http://go.microsoft.com/fwlink/?LinkId=85236
        readonly string[] dependsOnPropertyNames;

        // This is a positional argument
        public DependsOnAttribute(params string[] dependsOnPropertyNames)
        {
            this.dependsOnPropertyNames = dependsOnPropertyNames;
        }

        public string[] DependsOnPropertyNames
        {
            get { return dependsOnPropertyNames; }
        }

        // This is a named argument
        public int NamedInt { get; set; }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/17/a-nicer-way-to-handle-dependent-values-on-propertychanged/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cracked Toilet Suite</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/13/cracked-toilet-suite/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/13/cracked-toilet-suite/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 04:07:52 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1360</guid>
		<description><![CDATA[I found this on a recent purchase, which totally sucks. Andrew over at Builders Discount Warehouse over at Slacks Creek have refused to accept any responsibility, so it is off to the Fair Trading Commission. I hope it doesn&#8217;t turn into a saga.]]></description>
			<content:encoded><![CDATA[<p>I found this on a recent purchase, which totally sucks.</p>
<p>Andrew
<phone number="0421649609"> over at Builders Discount Warehouse over at Slacks Creek have refused to accept any responsibility, so it is off to the Fair Trading Commission.</p>
<p><a href="http://www.redmountainsw.com/wordpress/files/2012/01/cracked_suite.jpg"><img src="http://www.redmountainsw.com/wordpress/files/2012/01/cracked_suite.jpg" alt="" title="Cracked Toilet Suite" width="800" height="462" class="alignleft size-full wp-image-1361" /></a></p>
<p>I hope it doesn&#8217;t turn into a saga.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/13/cracked-toilet-suite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 5 &#8211; ListBox with Checkboxes</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/09/silverlight-5-listbox-with-checkboxes/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/09/silverlight-5-listbox-with-checkboxes/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 10:23:23 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1357</guid>
		<description><![CDATA[This is how you make a Listbox show checkboxes for selection in Silverlight 5. &#60;ListBox x:Name=&#34;TestList&#34; SelectionMode=&#34;Multiple&#34;&#62; &#60;ListBox.ItemTemplate&#62; &#60;DataTemplate&#62; &#60;CheckBox IsChecked=&#34;{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}&#34; Content=&#34;{Binding}&#34; /&#62; &#60;/DataTemplate&#62; &#60;/ListBox.ItemTemplate&#62; &#60;/ListBox&#62; And here&#8217;s a bit of sample code to set it up public MainPage() { InitializeComponent(); SetupListBox(); } public void SetupListBox() { TestList.ItemsSource = new String[] { [...]]]></description>
			<content:encoded><![CDATA[<p>This is how you make a Listbox show checkboxes for selection in Silverlight 5.</p>
<pre class="brush: xml">
&lt;ListBox x:Name=&quot;TestList&quot; SelectionMode=&quot;Multiple&quot;&gt;
    &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
            &lt;CheckBox
               IsChecked=&quot;{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}&quot;
               Content=&quot;{Binding}&quot; /&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;
</pre>
<p>And here&#8217;s a bit of sample code to set it up</p>
<pre class="brush: c#">
public MainPage()
{
    InitializeComponent();
    SetupListBox();
}

public void SetupListBox()
{
    TestList.ItemsSource = new String[]
    {
        &quot;Andrew&quot;, &quot;Frasier&quot;, &quot;Mellon&quot;, &quot;Dale&quot;
    };
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/09/silverlight-5-listbox-with-checkboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Argentum Tela &#8211; links to posts</title>
		<link>http://www.redmountainsw.com/wordpress/2012/01/08/silverlight-designer/</link>
		<comments>http://www.redmountainsw.com/wordpress/2012/01/08/silverlight-designer/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 03:37:34 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1350</guid>
		<description><![CDATA[Argentum Tela: A Visual Studio-style designer/toolbox in Silverlight on Codeplex. (Live Demo) Google Search Damon Payne &#124; Run time is design time for AGT [0] Damon Payne &#124; Run time is design time for AGT [1] Damon Payne &#124; Run time is design time for AGT [2] Run time is design time for AGT [3] [...]]]></description>
			<content:encoded><![CDATA[<p>Argentum Tela: <a href="http://agt.codeplex.com/">A Visual Studio-style designer/toolbox in Silverlight</a> on Codeplex.<br />
(<a href="http://www.damonpayne.com/agt/">Live Demo</a>)<br />
<a href="http://www.google.com.au/search?q=Argentum+Tela+site%3Awww.damonpayne.com">Google Search</a></p>
<ol>
<li>Damon Payne | <a href="http://www.damonpayne.com/post/2008/09/14/Run-time-is-design-time-for-AGT-0.aspx">Run time is design time for AGT [0]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/14/Run-time-is-design-time-for-AGT-1.aspx">Damon Payne | Run time is design time for AGT [1]</a></li>
<li>Damon Payne | <a href="http://www.damonpayne.com/2008/09/15/RunTimeIsDesignTimeForAGT2.aspx">Run time is design time for AGT [2]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/16/Run-time-is-design-time-for-AGT-3.aspx">Run time is design time for AGT [3]</a></li>
<li>Damon Payne | <a href="http://www.damonpayne.com/post/2008/09/15/AGT1-and-AGT2.aspx">AGT[1] and AGT[2]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/18/Run-time-is-design-time-for-AGT-4.aspx">Damon Payne | Run time is design time for AGT [4]</a></li>
<li><a href="http://www.damonpayne.com/2008/09/18/RunTimeIsDesignTimeForAGT5.aspx">Damon Payne | Run time is design time for AGT [5]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/18/AGT4-and-AGT5.aspx">Damon Payne | AGT[4] and AGT[5]</a></li>
<li>Damon Payne | <a href="http://www.damonpayne.com/post/2008/09/19/Run-time-is-design-time-for-AGT-6.aspx">Run time is design time for AGT [6]</a></li>
<li>Damon Payne | <a href="http://www.damonpayne.com/post/2008/09/20/Run-time-is-design-time-for-AGT-7.aspx">Run time is design time for AGT [7]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/21/Run-time-is-design-time-for-AGT8.aspx">Damon Payne | Run time is design time for AGT [8]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/22/Run-time-is-design-time-for-AGT9.aspx">Run time is design time for AGT[9]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/09/23/Run-time-is-design-time-for-AGT-10.aspx">Damon Payne | Run time is design time for AGT [10]</a></li>
<li>Damon Payne | <a href="http://www.damonpayne.com/post/2008/09/27/Run-time-is-design-time-for-AGT-11.aspx">Run time is design time for AGT [11]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/10/07/Run-time-is-design-time-for-AGT-12.aspx">Damon Payne | Run time is design time for AGT [12]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/10/10/Run-time-is-design-time-for-AGT-13.aspx">Damon Payne | Run time is design time for AGT [13]</a></li>
<li>Damon Payne | Run time is design time for AGT [14]</li>
<li><a href="http://www.damonpayne.com/post/2008/10/30/Run-time-is-design-time-for-AGT-15.aspx">Run time is design time for AGT [15]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/11/06/Run-time-is-design-time-for-AGT16.aspx">Damon Payne | Run time is design time for AGT[16]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/12/02/Run-time-is-design-time-for-AGT17.aspx">Damon Payne | Run time is design time for AGT[17]</a></li>
<li><a href="http://www.damonpayne.com/post/2008/12/12/Argentum-Tela-Design-Surface18.aspx">Damon Payne | Argentum Tela Design Surface[18]</a></li>
<li><a href="http://www.damonpayne.com/post/2009/01/12/Argentum-Tela-Design-Surface19.aspx">Damon Payne | Argentum Tela Design Surface[19]</a></li>
<li><a href="http://www.damonpayne.com/post/2009/09/25/Argentum-Tela-Design-Surface-20-ndash;-Getting-up-to-speed.aspx">Argentum Tela Design Surface [20] &ndash; Getting up to speed</a></li>
<li><a href="http://www.damonpayne.com/post/2009/10/05/Argentum-Tela-Design-Surface-21-ndash;-Name-Provider.aspx">Argentum Tela Design Surface [21] &#8211; Name Provider</a></li>
<li><a href="http://www.damonpayne.com/post/2008/11/19/SIG-talk-debriefing.aspx">SIG talk</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2012/01/08/silverlight-designer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

