I have a ListView which is created by class in ObservableCollection

public class ImageClass { public int Id { get; set; } public string ImagePath { get; set; } } 

Collection: PhotoList = new ObservableCollection<ImageClass>(); Well, actually filling: ImageList.ItemsSource = PhotoList;

ListView:

 <ListView x:Name="ImageList" > <ListView.ItemTemplate> <DataTemplate> <StackPanel HorizontalAlignment="Stretch" Margin="0,0,0,9"> <Image Height="Auto" HorizontalAlignment="Stretch" Source="{Binding ImagePath}" /> <StackPanel Orientation="Horizontal" Height="50" Background="#FFC2C9D0" HorizontalAlignment="Stretch"> <RadioButton GroupName="State" FontSize="25" Content="-" /> <RadioButton GroupName="State" FontSize="25" Content="+;" VerticalAlignment="Stretch" /> </StackPanel> </StackPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> 

enter image description here

And I can’t figure out how to make RadioButton + or - pressing this data somehow saved (for example, in the class where the link to the image lies) the selected RadioButton were in the same down position. The main difficulty is how to write RadioButton data to the desired one from the many created ImageClass. Please push the thought :)

    1 answer 1

    Instead of two radiobuttons, you can use the checkbox and add the bool IsChecked field in the collection model, in which to save the value of the checkbox. Well, or if radio beats are needed, then do it by analogy.

    • But I create my own class for each picture, as I understand it. And the difficulty itself is to explain the button that it will change this field in the class in which the picture is located above - Denisok
    • In PhotoList you have a collection of all the images with id. Add another property to ImageClass that will be responsible for the button state. Then do the bidirectional binding of the checkbox to this property and that's it. - Make Makeluv
    • Now I will try ...) - Denisok
    • Everything turned out, thanks) - Denisok