MultiBinding By Code ??
-
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 ?
-
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 ?
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 ?