Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - XAML extension question

 
 
Old 06-20-2007   #1 (permalink)
Lloyd Dupont


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
Is it possible to include XAML files into another XAML file? .NET General
Extension Method Question for ServicedComponent .NET General


Vista Forums 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 Ltd

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