Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
in nested class below (WPF program)
i could not populate the comboBox1 and comboBox2 with data (Mv[0].Vp and Mv[1].Vp) see line A and line B
the comboBoxes are empty.


What I have tried:

<pre lang="C#"><pre>
        public class VIDEOPERSON
        {
            public string VideoName { get; set; }
        }

        public class MainVideO
        {   public VIDEOPERSON[] Vp;
            public MainVideO() { }
            public VIDEOPERSON this[int i]
            { get { return Vp[i]; } set { Vp[i] = value; } }
        }
		    //more part of the MainWindow.cs program
			MainVideO[] Mv = new MainVideO[2];
            for (int i = 0; i < 2; i++)
            {
                Mv[i] = new MainVideO();
                Mv[i].Vp = new VIDEOPERSON[5];
                for (int j = 0; j < 5; j++) Mv[i].Vp[j] = new VIDEOPERSON();
            }

		//more code from MainWindow.xaml.cs
		Mv[0].Vp[0].VideoName = "D:\\Chees00";
		Mv[0].Vp[1].VideoName = "D:\\Chees01";
		Mv[0].Vp[2].VideoName = "D:\\Chees02";
		//
		Mv[1].Vp[0].VideoName = "D:\\Chees10";
		Mv[1].Vp[1].VideoName = "D:\\Chees11";
		Mv[1].Vp[2].VideoName = "D:\\Chees12";
XML
<pre>		<ComboBox x:Name="ComboBox1" Grid.Row="0" Grid.Column="2">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Mv[0].Vp}"/>  <!--"Line A"-->
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
        <!---->
        <ComboBox x:Name="ComboBox2" Grid.Row="0" Grid.Column="3">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Mv[1].Vp}"/>  <!--"Line B"-->
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
Posted
Updated 3-Oct-21 19:27pm
v3
Comments
[no name] 30-Sep-21 13:58pm    
You're binding to Mv; Mv is a local variable / field; not a property.
Engineer khalid 4-Oct-21 1:25am    
that was my 1st wpf program
i will use the program below...thanks any way

1 solution

public class VIDEOPERSON{public string VIDEONAME { get ; set ;}}
.
.
public List<VIDEOPERSON> VideoPerson = new List<VIDEOPERSON>();
//
VideoPerson.Add(new VIDEOPERSON { VIDEONAME = "D:\\aWPFc#\\ProgramByHelpFrmUTube\\WPFControls_2\\WPFControls_1\\Chees00.mp4" });
VideoPerson.Add(new VIDEOPERSON { VIDEONAME = "D:\\aWPFc#\\ProgramByHelpFrmUTube\\WPFControls_2\\WPFControls_1\\Chees01.mp4" });
VideoPerson.Add(new VIDEOPERSON { VIDEONAME = "D:\\aWPFc#\\ProgramByHelpFrmUTube\\WPFControls_2\\WPFControls_1\\Chees02.mp4" });
ComboBox1Mp4.ItemsSource = VideoPerson;
//.....
.
.
private void ComboBox2Mp4SelectionChangedClick(object sender, SelectionChangedEventArgs e)
{
int id = ComboBox1Mp4.SelectedIndex;
Uri ww;
ww = new System.Uri(VideoPerson[id].VIDEONAME);
Media1.Source = ww;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900