<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
On 09/02/2010 14:29, Edward J. Stembler wrote:
<blockquote cite="mid:96599742-CB70-448F-BA3C-79BF3A6F75C2@mac.com"
 type="cite">
  <div>You're correct, you cannot bind to a color.</div>
  <div><br>
  </div>
  <div>I do something similar in my C# Silverlight 3 project, where I
had to create a ColorToSolidBrushConverter.<br>
  </div>
</blockquote>
Right, and I can't do that from pure-Python with Silverlight. Binding
to the .Fill on the ellipsis wouldn't be a problem. Maybe I just need
to write the ValueConverter in C#. The issue is that the objects we're
binding too are written in straight Python, but we do use clrtype so it
might work (except that we still might have to setup the binding in
xaml whereas at the moment we can do it all programmatically, but oh
well).<br>
<br>
Thanks<br>
<br>
Michael<br>
<br>
<blockquote cite="mid:96599742-CB70-448F-BA3C-79BF3A6F75C2@mac.com"
 type="cite">
  <div><br>
On Feb 9, 2010, at 6:03 AM, Michael Foord &lt;<a moz-do-not-send="true"
 href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt;
wrote:<br>
  <br>
  </div>
  <blockquote type="cite">
    <div>On 09/02/2010 03:07, Dino Viehland wrote:
    <blockquote
 cite="mid:1A472770E042064698CB5ADC83A12ACD392C2DAC@TK5EX14MBXC116.redmond.corp.microsoft.com"
 type="cite">
      <style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
  </style><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
      <div class="Section1">
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">On
the
IValueConverter side of things: I haven’t debugged
through this but I have a guess as to what could be going on.  When we
emit a
type via reflection I don’t believe it’s available via Type.GetType
– which is the way types usually get loaded by name.  If you attach a
debugger I think you’d probably see an exception when trying to load
the
type.<o:p></o:p></span></p>
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
      </div>
    </blockquote>
Thanks for the reply. Looks like an IValueConverter based solution is
doomed to failure with IronPython and Silverlight.<br>
    <br>
    <blockquote
 cite="mid:1A472770E042064698CB5ADC83A12ACD392C2DAC@TK5EX14MBXC116.redmond.corp.microsoft.com"
 type="cite">
      <div class="Section1">
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">The
usual
solution for this would be to combine pre-compiled
subtypes and then save the generated type to disk and re-load it.  You
need the
pre-compiled subtypes because you can’t reference a transient assembly
(which
our in-memory subtypes are) from a non-transient one.  But that’s not
going to be immediately viable in Silverlight because the pre-compiled
type
will be a desktop CLR type.  So you could use pre-compiled types on the
desktop
and try to re-write the generated assembly but it seems like that’s
never
worked for anyone in the past.  <o:p></o:p></span></p>
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);">I
have
no clue on the PARSER_BAD_PROPERTY_VALUE error.</span></p>
      </div>
    </blockquote>
    <br>
I asked this same question on Stack Overflow [1]  and someone said that
you can't bind to a Color at all until Silverlight 4. Maybe that is the
reason for the parser error. My colleague is suggesting that maybe we
can use the new Silverlight 3 Feature "Element to Element Binding" [2],
so I will look into that.<br>
    <br>
All the best,<br>
    <br>
    <br>
Michael<br>
    <br>
[1]
    <a moz-do-not-send="true"
 href="http://stackoverflow.com/questions/2224805/silverlight-databinding-with-ironpython-and-datagrid">http://stackoverflow.com/questions/2224805/silverlight-databinding-with-ironpython-and-datagrid</a><br>
[2]
    <a moz-do-not-send="true"
 href="http://weblogs.asp.net/dwahlin/archive/2009/07/13/using-element-to-element-binding-for-tooltips-in-silverlight-3.aspx">http://weblogs.asp.net/dwahlin/archive/2009/07/13/using-element-to-element-binding-for-tooltips-in-silverlight-3.aspx</a><br>
    <blockquote
 cite="mid:1A472770E042064698CB5ADC83A12ACD392C2DAC@TK5EX14MBXC116.redmond.corp.microsoft.com"
 type="cite">
      <div class="Section1">
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p></o:p></span></p>
      <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: &quot;Calibri&quot;,&quot;sans-serif&quot;; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
      <div
 style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;">
      <div>
      <div
 style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">
      <p class="MsoNormal"><b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;; color: windowtext;">From:</span></b><span
 style="font-size: 10pt; font-family: &quot;Tahoma&quot;,&quot;sans-serif&quot;; color: windowtext;">
      <a moz-do-not-send="true"
 href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>
[<a moz-do-not-send="true"
 href="mailto:users-bounces@lists.ironpython.com">mailto:users-bounces@lists.ironpython.com</a>]
      <b>On Behalf Of </b>Michael
Foord<br>
      <b>Sent:</b> Monday, February 08, 2010 12:21 PM<br>
      <b>To:</b> Discussion of IronPython<br>
      <b>Subject:</b> [IronPython] Databinding a color in the datagrid
in
Silverlight<o:p></o:p></span></p>
      </div>
      </div>
      <p class="MsoNormal"><o:p> </o:p></p>
      <p class="MsoNormal">Hello all,<br>
      <br>
We've been successfully using clrtype with IronPython 2.6 and
Silverlight for
databinding, based on the example provided by Lukáš:<br>
      <br>
    <a moz-do-not-send="true"
 href="http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databinding.html">http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databinding.html</a><br>
      <br>
We create the binding when we create the datagrid columns
programatically.<br>
      <br>
Today I've been trying (and failing) to get a column in the grid show
different
colors based on databinding.<br>
      <br>
I've got the colored bubble *showing* in the grid, but can't get
databinding to
the color to work.  First the basics.<br>
      <br>
This is the xaml for the bubble with a fixed color:<br>
      <br>
&lt;DataTemplate xmlns='<a moz-do-not-send="true"
 href="http://schemas.microsoft.com/client/2007">http://schemas.microsoft.com/client/2007</a>'<br>
 xmlns:x='<a moz-do-not-send="true"
 href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>'&gt;<br>
    &lt;Ellipse Stroke="#FF222222"
Height="15" Width="15"&gt;<br>
        &lt;Ellipse.Fill&gt;<br>
           &lt;LinearGradientBrush
EndPoint="0.5,1" StartPoint="0.5,0"&gt;<br>
             
&lt;GradientStop x:Name="bubbleColor" Offset="0.694"<br>
              
Color="#FF00FF40" /&gt;<br>
             
&lt;GradientStop Color="#FFE6E6E6"/&gt;<br>
          
&lt;/LinearGradientBrush&gt;<br>
        &lt;/Ellipse.Fill&gt;<br>
    &lt;/Ellipse&gt;<br>
&lt;/DataTemplate&gt;<br>
      <br>
I can add a column based on this template very simply:<br>
      <br>
        from com_modules.loadxaml import
loadXaml<br>
        from System.Windows.Controls import
DataGridTemplateColumn<br>
        column = DataGridTemplateColumn()<br>
        column.CellTemplate =
loadXaml('templatecolumn')<br>
        column.Header = 'Bubble'<br>
        <br>
        grid.Columns.Add(column)<br>
      <br>
If I try to naively specify a binding in the xaml then I get a
PARSER_BAD_PROPERTY_VALUE when I attempt to load the xaml (so no hope
of
setting up the binding after load):<br>
      <br>
    &lt;GradientStop x:Name="bubbleColor"
Offset="0.694" Color="{Binding color}" /&gt;<br>
      <br>
      <br>
One approach I tried was to create a ValueConverter. Here is the
skeleton of
the class I created:<br>
      <br>
from System import Type<br>
from System.Globalization import CultureInfo<br>
from System.Windows.Data import IValueConverter<br>
      <br>
class ColorConverter(IValueConverter):<br>
    _clrnamespace = "Converters"<br>
    __metaclass__ = clrtype.ClrClass<br>
    <br>
    @clrtype.accepts(object, Type, object, CultureInfo)<br>
    @clrtype.returns(object)<br>
    def Convert(self, value, targetType, parameter, culture):<br>
        pass<br>
    <br>
    @clrtype.accepts(object, Type, object, CultureInfo)<br>
    @clrtype.returns(object)<br>
    def ConvertBack(self, value, targetType, parameter, culture):<br>
        pass<br>
      <br>
As there is a _clrnamespace specified I thought I might then be able to
use
this converter in xaml. Trying to reference the ColorConverter class in
the
Converters namespace in a resources dictionary again causes blow ups
when
loading the xaml.<br>
      <br>
Setting this up programatically would be ideal. Anyone got any ideas?<br>
      <br>
All the best,<br>
      <br>
Michael<br>
      <br>
      <br>
      <o:p></o:p></p>
      <pre>-- <o:p></o:p></pre>
      <pre><a moz-do-not-send="true"
 href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre>
      <pre><a moz-do-not-send="true"
 href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><o:p></o:p></pre>
      <pre><o:p> </o:p></pre>
      <pre>READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.<o:p></o:p></pre>
      <pre><o:p> </o:p></pre>
      <p class="MsoNormal"><br>
      <br>
      <o:p></o:p></p>
      <pre>-- <o:p></o:p></pre>
      <pre><a moz-do-not-send="true"
 href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre>
      <pre><a moz-do-not-send="true"
 href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><o:p></o:p></pre>
      <pre><o:p> </o:p></pre>
      <pre>READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.<o:p></o:p></pre>
      <pre><o:p> </o:p></pre>
      </div>
      </div>
      <pre wrap=""><fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Users mailing list
<a moz-do-not-send="true" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a moz-do-not-send="true"
 href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  </pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
<a moz-do-not-send="true" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a moz-do-not-send="true" href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

    </pre>
    </div>
  </blockquote>
  <blockquote type="cite">
    <div><span>_______________________________________________</span><br>
    <span>Users mailing list</span><br>
    <span><a moz-do-not-send="true"
 href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a></span><br>
    <span><a moz-do-not-send="true"
 href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></span><br>
    </div>
  </blockquote>
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a></pre>
</body>
</html>