On 09/02/2010 03:07, 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.
Thanks for the reply. Looks like an IValueConverter based solution is
doomed to failure with IronPython and Silverlight.
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.
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.
All the best,
Michael
[1]
http://stackoverflow.com/questions/2224805/silverlight-databinding-with-ironpython-and-datagrid
[2]
http://weblogs.asp.net/dwahlin/archive/2009/07/13/using-element-to-element-binding-for-tooltips-in-silverlight-3.aspx
*From:* [email protected]
<mailto:[email protected]>
[mailto:[email protected]] *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
[email protected] <mailto:[email protected]>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
--
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
[email protected] <mailto:[email protected]>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com