Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

XAML extension question

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-20-2007   #1 (permalink)
Lloyd Dupont
Guest


 

XAML extension question

In my application I want to display some data in a list box.
I need to display the data as a picture.

My 1st idea was to create a ValueConverter to convert my datas to
ImageSource
But this has a few problem, the biggest one is there is no parameter!
So I though of MarkupExtension
something like that:
<ListBox ItemsSource={Binding Document.Maps}>
<ItemTemplate>
<Image Source="{local:Map2Image PreviewDpi=24, Background=false}" />
</ItemTemplate>
</ListBox>

but here, problem, in the Map2ImageExtension.ProvideValue(IServiceProvider)
I don't ave the current data, worst, I have no idea to get it.

I was able to get the IProvideValueTarget but it only knows about the
"Image" object, not about the current item.
I tried to look into the "Binding" and "BindingBase" code with reflector,
but I don't understand what's going on...
Any tip?


Otherwise I could write a specialized viewer FrameworkElement, but I though
of using MarkupExtension might be a nice way to solve the problem....


My System SpecsSystem Spec
Old 07-03-2007   #2 (permalink)
Horst Klein
Guest


 

RE: XAML extension question

Hi Lloyd


I don't have an answer to your problem. Sorry.
But today I have the same problem and don't know how to get the instance of
the ServiceProvider.

In my case I want get the "ObjectDataProvider"
How can tell us how we can get our ServiceObjects?


My Xaml:

<ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type
VFC:GetDataCommand}" MethodName="Execute">
.....

<StackPanel VFWesignView.DataContext="{Binding
Source={VFW:MyDynamicResource VitoPatient},
Path=ParentObjects[Person__Patient]}">
.....

My Class:

<MarkupExtensionReturnType(GetType(Object)),
TypeConverter(GetType(DynamicResourceExtensionConverter))> _
Public Class MyDynamicResource
Inherits System.Windows.DynamicResourceExtension

Public Overrides Function ProvideValue(ByVal serviceProvider As
System.IServiceProvider) As Object
If (Not VitoResourceManager.DesignMode) Then
If (GetType(ObjectDataProvider).IsInstanceOfType(serviceProvider))
Then
Return MyBase.ProvideValue(serviceProvider)
Else
Return MyBase.ProvideValue(serviceProvider)
End If
Else
Return VitoApplication.FindDynamicResource(Me.ResourceKey.ToString)
End If
End Function

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal resourceKey As Object)
MyBase.New(resourceKey)
End Sub

End Class

My System SpecsSystem Spec
Old 07-04-2007   #3 (permalink)
Lloyd Dupont
Guest


 

Re: XAML extension question

Hi,

--
> Hi Lloyd
>
>
> I don't have an answer to your problem. Sorry.
> But today I have the same problem and don't know how to get the instance
> of
> the ServiceProvider.
>
> In my case I want get the "ObjectDataProvider"
> How can tell us how we can get our ServiceObjects?
>
>

when I read you VB code it looks a bit strange to me... :-/
anyway here is pseudo C# code (i.e. from the top of my head) to lookup for
object by name (define before the object using this markp extension, same
restriction as in StaticResource)

class MyMarkup : MarkupExtension
{
public object ProvideValue(IServiceProvider sp)
{
if(sp == null)
return null
IProvideValueTarget pvt =
(IProvideValueTarget)sp.GetService(typeof(IProvideValueTarget));
if(pvt == null)
return null;
FrameworkElement fe = pvt.Target as FrameworkElement;
if(fe == null)
return null;

DependencyObject do = fr.FindName("aName");
// ... whatever you need to ...
}
}

My System SpecsSystem Spec
Old 07-04-2007   #4 (permalink)
Horst Klein
Guest


 

Re: XAML extension question

Hi Lloyd

Thanks a lot that looks good to get the TargetObjetct.

But How can I get the Source?

In my case the
<ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type
VFC:GetDataCommand}" MethodName="Execute">

Best regards Horst
My System SpecsSystem Spec
Old 07-05-2007   #5 (permalink)
Lloyd Dupont
Guest


 

Re: XAML extension question

mmhh... I don't understand the question?..
what is this source you talk about?

anyway your only hope is a FindName() (or FindResource()) call to get other
object on the UI.
Binding use an internal Expression class which sets up event listener and
can


"Horst Klein" <HorstKlein@discussions.microsoft.com> wrote in message
news:47CB3366-391E-462B-A550-BE9D978813DC@microsoft.com...
> Hi Lloyd
>
> Thanks a lot that looks good to get the TargetObjetct.
>
> But How can I get the Source?
>
> In my case the
> <ObjectDataProvider x:Key="VitoPatient" ObjectType="{x:Type
> VFC:GetDataCommand}" MethodName="Execute">
>
> Best regards Horst



My System SpecsSystem Spec
Old 07-06-2007   #6 (permalink)
Florian Kruesch
Guest


 

Re: XAML extension question

Hi,

back to your original point. Surely you can pass a parameter to
a ValueConverter, using the ConverterParameter argument in the binding
expression. If you need to pass multiple parameters, you could parse
a string or use array-extension to pass in an array as parameter.

cheers
Florian
My System SpecsSystem Spec
Old 07-06-2007   #7 (permalink)
Florian Kruesch
Guest


 

Re: XAML extension question

Hi,

back to your original point. Surely you can pass a parameter to
a ValueConverter, using the ConverterParameter argument in the binding
expression. If you need to pass multiple parameters, you could parse
a string or use array-extension to pass in an array as parameter.

cheers
Florian
My System SpecsSystem Spec
Old 07-07-2007   #8 (permalink)
Lloyd Dupont
Guest


 

Re: XAML extension question

Yea, I saw that.
I was just mistakenly assuming that the Converter property took a
TypeConverter, whereas, as I later realized, it takes an IValueConverter
(which is different, of course).

anyway, this problem is long solved!! ;-)


"Florian Kruesch" <nospam@kruesch.de> wrote in message
news:468E7C81.1030404@kruesch.de...
> Hi,
>
> back to your original point. Surely you can pass a parameter to
> a ValueConverter, using the ConverterParameter argument in the binding
> expression. If you need to pass multiple parameters, you could parse
> a string or use array-extension to pass in an array as parameter.
>
> cheers
> Florian



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to include XAML files into another XAML file? star-italia .NET General 6 06-12-2008 04:56 AM
Extension Method Question for ServicedComponent coconet .NET General 1 04-06-2008 03:23 PM
Simple XAML Question ! MarkS Avalon 8 01-12-2007 11:10 AM
How to deploy an XAML-based App with its XAML-UI-File? Solveigh Avalon 11 11-08-2006 07:50 AM
Question about Listview, XAML, and hover. Whitey Avalon 0 10-11-2006 10:48 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51