[IronPython] StaticResources + DLR + Silverlight

Jimmy Schementi Jimmy.Schementi at microsoft.com
Wed Jul 2 23:23:02 CEST 2008


Dan Eloff wrote:
> I was reading your blog and it turns out you and I are the same age. Go
> figure.

Great to see a youngin' around here =)

> I tried this out, and it works great. There's one major problem with
> it though. It doesn't work with templating. LoadComponent has no
> overload that accepts a xaml string (or loaded application object).
> The current workaround I'd have to use is to evaluate the template,
> upload the generated xaml to the server, get a dynamic uri back, and
> load the xaml back down with LoadComponent. Very nasty.

Painful indeed! Does XamlReader.Load work for Resources? Are you specifically templating the Resources? If not, you could use LoadComponent for those, and then XamlReader.Load to load "normal" XAML.

Anyway, if you could give me a repro of what you're trying to do I could answer these questions for you. =)

Also, I'm assuming your doing the templating on the client for a reason ... =)

> Please, please
> push to get an lower-level overload of LoadComponent that takes xaml
> instead of a Uri (probably there already is such a beast, it's just
> not public.)

Looking at System.Windows.dll with Reflector, Application.LoadComponent calls MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, uint cUriStringLength, string uriString, uint cXamlStrLength, byte* pXamlStr), so yeah, there could be a wrapper. If XamlReader.Load doesn't work for this, I'll ask around.

> Thanks,
> -Dan

~Jimmy

> On Wed, Jun 25, 2008 at 7:55 PM, Jimmy Schementi
> <Jimmy.Schementi at microsoft.com> wrote:
> >
> > Using a dynamic language in Silverlight is no different than in C#/VB
> wrt StaticResources; you can have a app.xaml file which looks like
> this:
> >
> > <Application
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> >             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> >
> x:Class="Microsoft.Scripting.Silverlight.DynamicApplication"
> >             >
> >    <Application.Resources>
> >
> >    </Application.Resources>
> > </Application>
> >
> > And load it in app.py like this:
> >
> > Application.LoadComponent(Application.current, Uri("app.xaml",
> UriKind.Relative))
> >
> > I omit this "StaticResource XAML file" from our templates since I
> figured they'd only add confusion, but do you think this should be in
> there regardless?
> >
> > ~Jimmy
> >
> >> -----Original Message-----
> >> From: users-bounces at lists.ironpython.com [mailto:users-
> >> bounces at lists.ironpython.com] On Behalf Of Dan Eloff
> >> Sent: Monday, May 05, 2008 6:44 AM
> >> To: Discussion of IronPython
> >> Subject: [IronPython] StaticResources + DLR + Silverlight
> >>
> >> I notice if you use C#/VB, you have <Application> in your main xaml
> >> file. In there you can place resources that can be used from
> anywhere
> >> in your other xaml files. Using the {StaticResource foo}  markup
> >> extension.
> >>
> >> If you are using a dynamic language, there is no
> <DynamicApplication>
> >> equivalent (please correct me if I'm wrong), most examples I've seen
> >> use <UserControl>.
> >>
> >> The trouble is placing your resources in <UserControl.Resources>
> makes
> >> them off limit to {StaticResource foo} in any other xaml files
> (again
> >> please correct me if I'm wrong)
> >>
> >> So I find myself in a nightmare of duplicating resources across
> files
> >> and setting styles in code from
> >> Application.Current.RootVisual.Resources['foo'], neither of which is
> >> pleasant. Are there really no better alternatives?
> >>
> >> -Dan
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> > _______________________________________________
> > Users mailing list
> > Users at lists.ironpython.com
> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list