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> 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ΠΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π²ΠΎΠΏΡΠΎΡ Π½Π΅ Π·Π°ΡΡΠ°Π³ΠΈΠ²Π°Π΅Ρ 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)? - EvgeniyZRadioButton, and the value isList<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