<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@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;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></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]--></head><body bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I believe Silverlight 4 supports DataBinding on DependencyObjects, like Brush and Animation, so binding to a SolidColorBrush will work.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On Behalf Of </b>Michael Foord<br><b>Sent:</b> Tuesday, February 09, 2010 6:34 AM<br><b>To:</b> Discussion of IronPython<br><b>Cc:</b> stephan.mitt@comsulting.de<br><b>Subject:</b> Re: [IronPython] Databinding a color in the datagrid in Silverlight<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>On 09/02/2010 14:29, Edward J. Stembler wrote: <o:p></o:p></p><div><p class=MsoNormal>You're correct, you cannot bind to a color.<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>I do something similar in my C# Silverlight 3 project, where I had to create a ColorToSolidBrushConverter.<o:p></o:p></p></div><p class=MsoNormal>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><br><o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'><br>On Feb 9, 2010, at 6:03 AM, Michael Foord &lt;<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>&gt; wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>On 09/02/2010 03:07, Dino Viehland wrote: <o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>On the IValueConverter side of things: I haven’t debugged through this but I have a guess as to what could be going on.&nbsp; 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.&nbsp; If you attach a debugger I think you’d probably see an exception when trying to load the type.</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal>Thanks for the reply. Looks like an IValueConverter based solution is doomed to failure with IronPython and Silverlight.<br><br><br><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The usual solution for this would be to combine pre-compiled subtypes and then save the generated type to disk and re-load it.&nbsp; 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.&nbsp; But that’s not going to be immediately viable in Silverlight because the pre-compiled type will be a desktop CLR type.&nbsp; 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.&nbsp; </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I have no clue on the PARSER_BAD_PROPERTY_VALUE error.</span><o:p></o:p></p><p class=MsoNormal><br>I asked this same question on Stack Overflow [1]&nbsp; 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 &quot;Element to Element Binding&quot; [2], so I will look into that.<br><br>All the best,<br><br><br>Michael<br><br>[1] <a 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 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><br><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;</span><o:p></o:p></p><div style='border:none;border-left:solid windowtext 1.5pt;padding:0in 0in 0in 4.0pt;border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color blue'><div><div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;border-color:-moz-use-text-color -moz-use-text-color'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [<a 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</span><o:p></o:p></p></div></div><p class=MsoNormal>&nbsp;<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>&nbsp;&nbsp;&nbsp; <a 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.&nbsp; First the basics.<br><br>This is the xaml for the bubble with a fixed color:<br><br>&lt;DataTemplate xmlns='<a href="http://schemas.microsoft.com/client/2007">http://schemas.microsoft.com/client/2007</a>'<br>&nbsp;xmlns:x='<a href="http://schemas.microsoft.com/winfx/2006/xaml">http://schemas.microsoft.com/winfx/2006/xaml</a>'&gt;<br>&nbsp;&nbsp;&nbsp; &lt;Ellipse Stroke=&quot;#FF222222&quot; Height=&quot;15&quot; Width=&quot;15&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Ellipse.Fill&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;LinearGradientBrush EndPoint=&quot;0.5,1&quot; StartPoint=&quot;0.5,0&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;GradientStop x:Name=&quot;bubbleColor&quot; Offset=&quot;0.694&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Color=&quot;#FF00FF40&quot; /&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;GradientStop Color=&quot;#FFE6E6E6&quot;/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/LinearGradientBrush&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Ellipse.Fill&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/Ellipse&gt;<br>&lt;/DataTemplate&gt;<br><br>I can add a column based on this template very simply:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from com_modules.loadxaml import loadXaml<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from System.Windows.Controls import DataGridTemplateColumn<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column = DataGridTemplateColumn()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column.CellTemplate = loadXaml('templatecolumn')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column.Header = 'Bubble'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; &lt;GradientStop x:Name=&quot;bubbleColor&quot; Offset=&quot;0.694&quot; Color=&quot;{Binding color}&quot; /&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>&nbsp;&nbsp;&nbsp; _clrnamespace = &quot;Converters&quot;<br>&nbsp;&nbsp;&nbsp; __metaclass__ = clrtype.ClrClass<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; @clrtype.accepts(object, Type, object, CultureInfo)<br>&nbsp;&nbsp;&nbsp; @clrtype.returns(object)<br>&nbsp;&nbsp;&nbsp; def Convert(self, value, targetType, parameter, culture):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; @clrtype.accepts(object, Type, object, CultureInfo)<br>&nbsp;&nbsp;&nbsp; @clrtype.returns(object)<br>&nbsp;&nbsp;&nbsp; def ConvertBack(self, value, targetType, parameter, culture):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre><pre><a href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><o:p></o:p></pre><pre>&nbsp;<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>&nbsp;<o:p></o:p></pre><p class=MsoNormal><br><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre><pre><a href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><o:p></o:p></pre><pre>&nbsp;<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>&nbsp;<o:p></o:p></pre></div><pre><o:p>&nbsp;</o:p></pre><pre>_______________________________________________<o:p></o:p></pre><pre>Users mailing list<o:p></o:p></pre><pre><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><o:p></o:p></pre><pre><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></pre><pre>  <o:p></o:p></pre><p class=MsoNormal><br><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre><pre><a href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a><o:p></o:p></pre><pre><o:p>&nbsp;</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>&nbsp;</o:p></pre><pre>    <o:p></o:p></pre></div></blockquote><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></p></div></blockquote><pre><o:p>&nbsp;</o:p></pre><pre><o:p>&nbsp;</o:p></pre><pre>_______________________________________________<o:p></o:p></pre><pre>Users mailing list<o:p></o:p></pre><pre><a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><o:p></o:p></pre><pre><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><o:p></o:p></pre><pre>  <o:p></o:p></pre><p class=MsoNormal><br><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><o:p></o:p></pre></div></div></body></html>