There is a collection of radiobutton , by clicking on each such button a collection of togglebutton is formed. The data for the formation of both lists is taken from the viewModel using binding .

Is there a way to save the state of the pressed buttons for each togglebutton . Ideally, I would like to highlight those radiobutton for which at least one toggle is selected.

 <!--Бписок Ρ€Π°Π΄ΠΈΠΎΠΊΠ½ΠΎΠΏΠΎΠΊ--> <ItemsControl Grid.Column="2" Grid.Row="2" Name="InDiamVM" Margin="2" ItemsSource="{Binding RebarsView}"> <!-- ItemsPanelTemplate --> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <!-- ItemTemplate --> <ItemsControl.ItemTemplate> <DataTemplate> <RadioButton GroupName="InDiam" Content="{Binding}" Command="{Binding Path=DataContext.ManageCurrntInDiamCommand, ElementName=InDiamVM}" Name="InDiamButtonVM" Style="{StaticResource StyleToggle}" Margin="1" Padding="2"> <RadioButton.CommandParameter> <MultiBinding Converter="{StaticResource CommandParameterConverter}"> <Binding ElementName="InDiamButtonVM" Path="Content" /> <Binding ElementName="InDiamButtonVM" Path="Name" /> </MultiBinding> </RadioButton.CommandParameter> </RadioButton> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> <!--Бписок togglebutton--> <ItemsControl Grid.Column="3" Grid.Row="2" Name="OutDiamVM" Margin="2" ItemsSource="{Binding OutDiameters}"> <!-- ItemsPanelTemplate --> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <!-- ItemTemplate --> <ItemsControl.ItemTemplate> <DataTemplate> <ToggleButton Content="{Binding }" Command="{Binding Path=DataContext.ManageCurrntOutDiamCommand, ElementName=OutDiamVM}" Name="OutDiamButtonVM" Margin="1" Padding="2"> <ToggleButton.CommandParameter> <MultiBinding Converter="{StaticResource CommandParameterConverter}"> <Binding ElementName="OutDiamButtonVM" Path="IsChecked" /> <Binding ElementName="OutDiamButtonVM" Path="Content" /> </MultiBinding> </ToggleButton.CommandParameter> </ToggleButton> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

enter image description here

The viewModel part that is responsible for the view.

 // DependencyProperty для ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ radiobutton public ICollectionView RebarsView { get { return (ICollectionView)GetValue(RebarsViewProperty); } set { SetValue(RebarsViewProperty, value); } } // Using a DependencyProperty as the backing store for RebarsView. This enables animation, styling, binding, etc... public static readonly DependencyProperty RebarsViewProperty = DependencyProperty.Register("RebarsView", typeof(ICollectionView), typeof(AnchorageViewModel), new PropertyMetadata(null)); // DependencyProperty для Π²Ρ‹Π±Ρ€Π°Π½Π½ΠΎΠΉ ΠΊΠ½ΠΎΠΏΠΊΠΈ radiobutton public RebarProperties FocusedRebar { get { return (RebarProperties)GetValue(FocusedRebarProperty); } set { SetValue(FocusedRebarProperty, value); } } // Using a DependencyProperty as the backing store for FocusedRebar. This enables animation, styling, binding, etc... public static readonly DependencyProperty FocusedRebarProperty = DependencyProperty.Register("FocusedRebar", typeof(RebarProperties), typeof(AnchorageViewModel), new PropertyMetadata(null)); // Команда для получСния Π½ΡƒΠΆΠ½ΠΎΠΉ ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π² зависимости ΠΎΡ‚ полоТСния radiobutton public RelayCommand ManageCurrntInDiamCommand { get; private set; } public void ManageCurrntInDiam(object o) { var parameters = o as object[]; FocusedRebar = parameters[0] as RebarProperties; if (FocusedSteel == null) { return; } //Π’Ρ‹Π±ΠΎΡ€ΠΊΠ° Π½ΡƒΠΆΠ½ΠΎΠ³ΠΎ массива для формирования ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ togglebutton OutDiameters = CollectionViewSource.GetDefaultView(FocusedSteel.DiametersPermitted.Where(s => s.Diameter <= FocusedRebar.Diameter)); } // DependencyProperty для ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ togglebutton public ICollectionView OutDiameters { get { return (ICollectionView)GetValue(OutDiametersProperty); } set { SetValue(OutDiametersProperty, value); } } // Using a DependencyProperty as the backing store for OutDiameters. This enables animation, styling, binding, etc... public static readonly DependencyProperty OutDiametersProperty = DependencyProperty.Register("OutDiameters", typeof(ICollectionView), typeof(AnchorageViewModel), new PropertyMetadata(null)); // DependencyProperty для ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹Ρ… toggle button public ObservableCollection<RebarProperties> currentOutDiams = new ObservableCollection<RebarProperties>(); public RelayCommand ManageCurrntOutDiamCommand { get; private set; } public void ManageCurrntOutDiam(object o) { var parameters = o as object[]; if ((bool)parameters[0] == true) { if (SteelToDiam.ContainsKey(FocusedSteel)) { if (SteelToDiam[FocusedSteel].ContainsKey(FocusedRebar)) { SteelToDiam[FocusedSteel][FocusedRebar].Add(parameters[1] as RebarProperties); } else { SteelToDiam[FocusedSteel].Add(FocusedRebar, new HashSet<RebarProperties>() { parameters[1] as RebarProperties }); } } else { SteelToDiam.Add(FocusedSteel, new Dictionary<RebarProperties, HashSet<RebarProperties>>() { {FocusedRebar, new HashSet<RebarProperties>() { parameters[1] as RebarProperties }} }); } } else { SteelToDiam[FocusedSteel][FocusedRebar].Remove(parameters[1] as RebarProperties); } // ΠΌΠ΅Ρ‚ΠΎΠ΄, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Ρ€Π΅Π°Π»ΠΈΠ·ΡƒΠ΅Ρ‚ ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΠΈ (Π² data grid, Π³Π΄Π΅ ΠΎΠ½Π° отобраТаСтся) UpdateInfo(); } 
  • Π•ΡΡ‚ΡŒ коллСкция radiobutton, ΠΏΠΎ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΈ Π½Π° ΠΊΠ°ΠΆΠ΄ΡƒΡŽ Ρ‚Π°ΠΊΡƒΡŽ ΠΊΠ½ΠΎΠΏΠΊΡƒ формируСтся коллСкция togglebutton. - show? If I understand this correctly, then you don’t feel like MVVM ... - EvgeniyZ
  • Perhaps the question does not affect MVVM. I have implemented a ViewModel that pulls the calculated data from Logic. I would like either in the ViewModel or directly in xaml to do what is in question: to keep the state of the clicked toggle button. - A.Balm
  • Π’ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ вопрос Π½Π΅ Π·Π°Ρ‚Ρ€Π°Π³ΠΈΠ²Π°Π΅Ρ‚ MVVM - and there is a label MVVM, and you are trying to use the MVVM approach because, how then Π½Π΅ Π·Π°Ρ‚Ρ€Π°Π³ΠΈΠ²Π°Π΅Ρ‚ it Π½Π΅ Π·Π°Ρ‚Ρ€Π°Π³ΠΈΠ²Π°Π΅Ρ‚ ? Well, since you have everything on MVVM, then forget about View, imagine that you simply do not have it. How would you implement this in code from primitive objects (int / string / bool ... and class)? - EvgeniyZ
  • And you try to make a dictionary. The key is RadioButton , and the value is List<ToggleButtons> . And when changing the state of at least one RadioButton, update the data - change the state of the ToggleButton to those that are in the dictionary according to the key of the active RadioButton. Should work - Aqua
  • And if it is not difficult, and the state of the project allows, you can leave a link to the xaml file so that you can prepare the answer yourself - Aqua

0