Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Custom Binding Path

Custom Binding Path

Scheduled Pinned Locked Moved WPF
wpfwcfdata-structurestutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fabrizio Camagna
    wrote on last edited by
    #1

    I have to realize a binding like this <TextBlock Text="{local:mybinding Path=folder1.folder2.item}" FontSize="16"/> in the Path I have a string but this doesn't correspond to an object tree, I would dynamically attach a real object that corresponds to this string. example folder1.folder2.item1 I create an object obj1=new MyObject("folder1.folder2.item1") example folder1.folder2.item2 I create an object obj2=new MyObject("folder1.folder2.item2") obj1 and obj2 are the real objects I want bind. Maybe it's possible with ExtensionMarkup but Silverlight 3 doesn't support it, do it? Do you have any solution?

    M 1 Reply Last reply
    0
    • F Fabrizio Camagna

      I have to realize a binding like this <TextBlock Text="{local:mybinding Path=folder1.folder2.item}" FontSize="16"/> in the Path I have a string but this doesn't correspond to an object tree, I would dynamically attach a real object that corresponds to this string. example folder1.folder2.item1 I create an object obj1=new MyObject("folder1.folder2.item1") example folder1.folder2.item2 I create an object obj2=new MyObject("folder1.folder2.item2") obj1 and obj2 are the real objects I want bind. Maybe it's possible with ExtensionMarkup but Silverlight 3 doesn't support it, do it? Do you have any solution?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Fabrizio Camagna wrote:

      <TextBlock Text="{local:mybinding Path=folder1.folder2.item}" FontSize="16"/>

      folder1.folder2.item is a path to a string or do you want to specify the string in markup?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      F 1 Reply Last reply
      0
      • M Mark Salsbery

        Fabrizio Camagna wrote:

        <TextBlock Text="{local:mybinding Path=folder1.folder2.item}" FontSize="16"/>

        folder1.folder2.item is a path to a string or do you want to specify the string in markup?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        F Offline
        F Offline
        Fabrizio Camagna
        wrote on last edited by
        #3

        is a path that rappresent a tree path of my "custom namespace" but the objects don't exist before I parse this string. I'd like parse this string and create these objects.

        M 1 Reply Last reply
        0
        • F Fabrizio Camagna

          is a path that rappresent a tree path of my "custom namespace" but the objects don't exist before I parse this string. I'd like parse this string and create these objects.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Maybe you could use a converter...

          public class MyObject
          {
              public MyObject(string str)
              {
                  //...
              }
          }
          
          public class StringToObjectConverter : IValueConverter
          {
              public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
              {
                  string str = (string)parameter;
                  return new MyObject(str);
              }
          
              public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
              {
                  throw new NotImplementedException();
              }
          }
          
          <UserControl.Resources>
              <local:StringToObjectConverter x:Name="StringToObjectConverter" />
          </UserControl.Resources>
          

          ...
          <TextBlock Text="{Binding Converter={StaticResource StringToObjectConverter}, ConverterParameter=folder1.folder2.item}" FontSize="16"/>

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups