XAML extension question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lloyd Dupont

    #1

    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={Bi nding Document.Maps}>
    <ItemTemplate >
    <Image Source="{local: Map2Image PreviewDpi=24, Background=fals e}" />
    </ItemTemplate>
    </ListBox>

    but here, problem, in the Map2ImageExtens ion.ProvideValu e(IServiceProvi der)
    I don't ave the current data, worst, I have no idea to get it.

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


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

  • =?Utf-8?B?SG9yc3QgS2xlaW4=?=

    #2
    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 "ObjectDataProv ider"
    How can tell us how we can get our ServiceObjects?


    My Xaml:

    <ObjectDataProv ider x:Key="VitoPati ent" ObjectType="{x: Type
    VFC:GetDataComm and}" MethodName="Exe cute">
    .....

    <StackPanel VFW:DesignView. DataContext="{B inding
    Source={VFW:MyD ynamicResource VitoPatient},
    Path=ParentObje cts[Person__Patient]}">
    .....

    My Class:

    <MarkupExtensio nReturnType(Get Type(Object)),
    TypeConverter(G etType(DynamicR esourceExtensio nConverter))_
    Public Class MyDynamicResour ce
    Inherits System.Windows. DynamicResource Extension

    Public Overrides Function ProvideValue(By Val serviceProvider As
    System.IService Provider) As Object
    If (Not VitoResourceMan ager.DesignMode ) Then
    If (GetType(Object DataProvider).I sInstanceOfType (serviceProvide r))
    Then
    Return MyBase.ProvideV alue(servicePro vider)
    Else
    Return MyBase.ProvideV alue(servicePro vider)
    End If
    Else
    Return VitoApplication .FindDynamicRes ource(Me.Resour ceKey.ToString)
    End If
    End Function

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

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

    End Class

    Comment

    • Lloyd Dupont

      #3
      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 "ObjectDataProv ider"
      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(IS erviceProvider sp)
      {
      if(sp == null)
      return null
      IProvideValueTa rget pvt =
      (IProvideValueT arget)sp.GetSer vice(typeof(IPr ovideValueTarge t));
      if(pvt == null)
      return null;
      FrameworkElemen t fe = pvt.Target as FrameworkElemen t;
      if(fe == null)
      return null;

      DependencyObjec t do = fr.FindName("aN ame");
      // ... whatever you need to ...
      }
      }

      Comment

      • =?Utf-8?B?SG9yc3QgS2xlaW4=?=

        #4
        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
        <ObjectDataProv ider x:Key="VitoPati ent" ObjectType="{x: Type
        VFC:GetDataComm and}" MethodName="Exe cute">

        Best regards Horst

        Comment

        • Lloyd Dupont

          #5
          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@dis cussions.micros oft.comwrote in message
          news:47CB3366-391E-462B-A550-BE9D978813DC@mi crosoft.com...
          Hi Lloyd
          >
          Thanks a lot that looks good to get the TargetObjetct.
          >
          But How can I get the Source?
          >
          In my case the
          <ObjectDataProv ider x:Key="VitoPati ent" ObjectType="{x: Type
          VFC:GetDataComm and}" MethodName="Exe cute">
          >
          Best regards Horst

          Comment

          Working...