Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

XAML extension question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lloyd Dupont - 20 Jun 2007 08:44 GMT
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....
Horst Klein - 03 Jul 2007 19:08 GMT
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 VFW:DesignView.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
Lloyd Dupont - 04 Jul 2007 06:36 GMT
Hi,

> Hi Lloyd
>
[quoted text clipped - 5 lines]
> 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 ...
   }
}
Horst Klein - 04 Jul 2007 08:10 GMT
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
Lloyd Dupont - 05 Jul 2007 14:01 GMT
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

> Hi Lloyd
>
[quoted text clipped - 7 lines]
>
> Best regards Horst

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.