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. WCF and WF
  4. MultiBinding By Code ??

MultiBinding By Code ??

Scheduled Pinned Locked Moved WCF and WF
2 Posts 1 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
    Feras Mazen Taleb
    wrote on last edited by
    #1

    hello , I have the following code in xaml to make multi Binding to Media Element using Convertor

    <MediaElement VerticalAlignment="Center" LoadedBehavior="Play"
    HorizontalAlignment="Center"
    x:Name="ReferenceMediaElement"
    Width="100" Height="100"
    IsMuted="True"
    MediaOpened="MediaElement_MediaOpened"
    MediaFailed="MediaElement_MediaFailed"
    MediaEnded="MediaElement_MediaEnded"
    >
    <MediaElement.Source>
    <MultiBinding Converter="{StaticResource RefConverter}" >
    <Binding Path="File" />
    <Binding Path="Extention" />
    <Binding Source="{StaticResource TempFilePath}" Mode="OneWay" />
    </MultiBinding>
    </MediaElement.Source>
    </MediaElement>

    how can I do the same thing but by code I mean in C# or VB Code I tried to use MultiBinding class And add Binding object to it but I faild :( and this my code :

    MediaElement M = new MediaElement();
    // make binding objects
    Binding SourceDataBinding = new Binding("SourceProperty");
    Binding SourceExtentionBinding = new Binding("SourceProperty");
    Binding SourcePathBinding = new Binding("SourceProperty");

    // make binding objects
    MultiBinding SourceBinding = new MultiBinding();
    SourceBinding.Bindings.Add(SourceDataBinding);
    SourceBinding.Bindings.Add(SourceExtentionBinding);
    SourceBinding.Bindings.Add(SourcePathBinding);
    // my converter class called ReferenceConverter
    SourceBinding.Converter = new ReferenceConverter();

    // set the binding object to Source
    M.SetBinding(MediaElement.SourceProperty, SourceBinding);

    You have To Search About The Truth Of Your Life Why Are you Here In Life ?

    F 1 Reply Last reply
    0
    • F Feras Mazen Taleb

      hello , I have the following code in xaml to make multi Binding to Media Element using Convertor

      <MediaElement VerticalAlignment="Center" LoadedBehavior="Play"
      HorizontalAlignment="Center"
      x:Name="ReferenceMediaElement"
      Width="100" Height="100"
      IsMuted="True"
      MediaOpened="MediaElement_MediaOpened"
      MediaFailed="MediaElement_MediaFailed"
      MediaEnded="MediaElement_MediaEnded"
      >
      <MediaElement.Source>
      <MultiBinding Converter="{StaticResource RefConverter}" >
      <Binding Path="File" />
      <Binding Path="Extention" />
      <Binding Source="{StaticResource TempFilePath}" Mode="OneWay" />
      </MultiBinding>
      </MediaElement.Source>
      </MediaElement>

      how can I do the same thing but by code I mean in C# or VB Code I tried to use MultiBinding class And add Binding object to it but I faild :( and this my code :

      MediaElement M = new MediaElement();
      // make binding objects
      Binding SourceDataBinding = new Binding("SourceProperty");
      Binding SourceExtentionBinding = new Binding("SourceProperty");
      Binding SourcePathBinding = new Binding("SourceProperty");

      // make binding objects
      MultiBinding SourceBinding = new MultiBinding();
      SourceBinding.Bindings.Add(SourceDataBinding);
      SourceBinding.Bindings.Add(SourceExtentionBinding);
      SourceBinding.Bindings.Add(SourcePathBinding);
      // my converter class called ReferenceConverter
      SourceBinding.Converter = new ReferenceConverter();

      // set the binding object to Source
      M.SetBinding(MediaElement.SourceProperty, SourceBinding);

      You have To Search About The Truth Of Your Life Why Are you Here In Life ?

      F Offline
      F Offline
      Feras Mazen Taleb
      wrote on last edited by
      #2

      Okay I found the answer I made two mistakes in previous thread: 1- I forget to set the source property for each Binding object 2- I called setBinding method for media Element before adding it to the window window contain button1 this code is wrong

              MediaELement M = new MediaElement();
              Binding SourceDataBinding = new Binding();
              SourceDataBinding.Source = data; // data is variable that contain the data to bind
              SourceDataBinding.Mode = BindingMode.OneWay;
      
              Binding SourceExtentionBinding = new Binding();
              SourceExtentionBinding.Source = Extension; // extension is variable that contain the data to bind
              SourceExtentionBinding.Mode = BindingMode.OneWay;
      
              Binding SourcePathBinding = new Binding();
              SourcePathBinding.Mode = BindingMode.OneWay;
              SourcePathBinding.Source = \_filePath; // \_filePath is variable that contain the data to bind
      
              MultiBinding SourceBinding = new MultiBinding();
              SourceBinding.Bindings.Add(SourceDataBinding);
              SourceBinding.Bindings.Add(SourceExtentionBinding);
              SourceBinding.Bindings.Add(SourcePathBinding);
              SourceBinding.Converter = new ReferenceConverter();
      
              M.SetBinding(MediaElement.SourceProperty, SourceBinding);
              this.button1.Content = M;
      

      this code is right

              this.button1.Content = M;
              MediaELement M = new MediaElement();
              Binding SourceDataBinding = new Binding();
              SourceDataBinding.Source = data;
              SourceDataBinding.Mode = BindingMode.OneWay;
      
              Binding SourceExtentionBinding = new Binding();
              SourceExtentionBinding.Source = Extension;
              SourceExtentionBinding.Mode = BindingMode.OneWay;
      
              Binding SourcePathBinding = new Binding();
              SourcePathBinding.Mode = BindingMode.OneWay;
              SourcePathBinding.Source = \_filePath;
      
              MultiBinding SourceBinding = new MultiBinding();
              SourceBinding.Bindings.Add(SourceDataBinding);
              SourceBinding.Bindings.Add(SourceExtentionBinding);
              SourceBinding.Bindings.Add(SourcePathBinding);
              SourceBinding.Converter = new ReferenceConverter();
      
              M.SetBinding(MediaElement.SourceProperty, SourceBinding);
      

      You have To Search About The Truth Of Your Life Why Are you Here In Life ?

      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