I've created a Listbox containing a series of instances of a custom class, and now I want to create a side panel with a number of checkboxes to show and alter their properties, but I'm having troubles with the binding.
Here's the code for the elements' class. I've omitted the constructors for brevity.
public class Film
{
private string t, p;
public GenreList Genres;
public class GenreList : INotifyPropertyChanged
{
private bool[] gen_lst;
public event PropertyChangedEventHandler PropertyChanged;
public GenreList(bool[] init)
{
gen_lst = init;
}
public bool this[int index]
{
get
{
return gen_lst[index];
}
set
{
gen_lst[index] = value;
OnPropertyChanged("this");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
public string Title
{
get
{
return t;
}
set
{
t = value;
}
}
public string Path
{
get
{
return p;
}
set
{
p = value;
}
}
}
And the XAML for one the CheckBoxes:
<CheckBox x:Name="Checkbox1" Content="Checkbox1" Grid.Column="1" HorizontalAlignment="Left" Height="15" Margin="13,25,0,0" VerticalAlignment="Top" Width="15" IsChecked="{Binding ElementName=Listbox1, Path = SelectedItem.Genres[0], Mode=TwoWay}"/>
As you see the class contains a bool[] managed as an indexed property, and I'd like to bind a checkbox to each element of the array. However, the binding doesn't seem to be working at all, the get method for the property is never called and the only visible effect is that, when I select a different element after checking the box, the box returns unchecked.
Listbox1.SelectedItem.Genres[index] works as intended if I try to use in the program body.
I hope the question was detailed enough, but if you need other parts of the code or the full program I'll provide them.
Aucun commentaire:
Enregistrer un commentaire