[IronPython] Databinding a color in the datagrid in Silverlight

Edward J. Stembler ejstembler at mac.com
Tue Feb 9 04:36:06 CET 2010


I guess in some ways this also addresses my post from January <http://lists.ironpython.com/pipermail/users-ironpython.com/2010-January/012013.html> which was never answered.


On Feb 8, 2010, at 10:07 PM, Dino Viehland wrote:

> 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.
>  
> 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. 
>  
> I have no clue on the PARSER_BAD_PROPERTY_VALUE error.
>  
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
> Sent: Monday, February 08, 2010 12:21 PM
> To: Discussion of IronPython
> Subject: [IronPython] Databinding a color in the datagrid in Silverlight
>  
> Hello all,
> 
> We've been successfully using clrtype with IronPython 2.6 and Silverlight for databinding, based on the example provided by Lukáš:
> 
>     http://gui-at.blogspot.com/2009/11/inotifypropertychanged-and-databinding.html
> 
> We create the binding when we create the datagrid columns programatically.
> 
> Today I've been trying (and failing) to get a column in the grid show different colors based on databinding.
> 
> I've got the colored bubble *showing* in the grid, but can't get databinding to the color to work.  First the basics.
> 
> This is the xaml for the bubble with a fixed color:
> 
> <DataTemplate xmlns='http://schemas.microsoft.com/client/2007'
>  xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
>     <Ellipse Stroke="#FF222222" Height="15" Width="15">
>         <Ellipse.Fill>
>            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
>               <GradientStop x:Name="bubbleColor" Offset="0.694"
>                Color="#FF00FF40" />
>               <GradientStop Color="#FFE6E6E6"/>
>            </LinearGradientBrush>
>         </Ellipse.Fill>
>     </Ellipse>
> </DataTemplate>
> 
> I can add a column based on this template very simply:
> 
>         from com_modules.loadxaml import loadXaml
>         from System.Windows.Controls import DataGridTemplateColumn
>         column = DataGridTemplateColumn()
>         column.CellTemplate = loadXaml('templatecolumn')
>         column.Header = 'Bubble'
>         
>         grid.Columns.Add(column)
> 
> 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):
> 
>     <GradientStop x:Name="bubbleColor" Offset="0.694" Color="{Binding color}" />
> 
> 
> One approach I tried was to create a ValueConverter. Here is the skeleton of the class I created:
> 
> from System import Type
> from System.Globalization import CultureInfo
> from System.Windows.Data import IValueConverter
> 
> class ColorConverter(IValueConverter):
>     _clrnamespace = "Converters"
>     __metaclass__ = clrtype.ClrClass
>     
>     @clrtype.accepts(object, Type, object, CultureInfo)
>     @clrtype.returns(object)
>     def Convert(self, value, targetType, parameter, culture):
>         pass
>     
>     @clrtype.accepts(object, Type, object, CultureInfo)
>     @clrtype.returns(object)
>     def ConvertBack(self, value, targetType, parameter, culture):
>         pass
> 
> 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.
> 
> Setting this up programatically would be ideal. Anyone got any ideas?
> 
> All the best,
> 
> Michael
> 
> 
> -- 
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/blog
>  
> 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.
>  
> 
> 
> -- 
> http://www.ironpythoninaction.com/
> http://www.voidspace.org.uk/blog
>  
> 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.
>  
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100208/a958656a/attachment.html>


More information about the Ironpython-users mailing list