Hello all,

We've been successfully using clrtype with IronPython 2.6 and Silverlight for databinding, based on the example provided by Lukás(:

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@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to