Здраствуйте! Мне нужно чтобы по RadioButton
выбирать активное поле или наоборот. Я сделал команду, но она почему то не работает. Что я делаю не так?
XAML
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Width="auto" Margin="0,0,0,10">
<RadioButton GroupName="Butons" x:Name="ActiveLocation" Content="Active" Width="80" Margin="5,0,0,0" Command="{Binding ActiveCommand}" >
</RadioButton>
<RadioButton GroupName="Butons" x:Name="InActiveLocation" Content="InActive" Width="80" Margin="5,0,0,0" Command="{Binding InActiveCommand}">
</RadioButton>
<RadioButton GroupName="Butons" x:Name="Alee" Width="80" Content="Alle" Margin="5,0,0,0" Command="{Binding AlleCommand}" IsChecked="True">
</RadioButton>
</StackPanel>
<dxg:GridControl Name="GridControl" ItemsSource="{Binding IndustriesCollections}" Grid.Row="2">
<dxg:GridControl.Columns >
<dxg:GridColumn Header="Gewerk" FieldName="NameProduct"/>
<dxg:GridColumn Header="MwSt" FieldName="CodeVat"/>
<dxg:GridColumn Header="S13B4" FieldName="Is13B4"/>
<dxg:GridColumn Header="Aktiv" FieldName="IsActive" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="TableView" ShowGroupPanel="False" MultiSelectMode="Row" IsTabStop="False" AllowLeaveFocusOnTab="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
C#
private readonly IEnumerable<IIndustries> _locationsIndustries;
public ObservableCollection<IIndustries> IndustriesCollections { get; private set; }
private ObservableCollection<IIndustries> NewCollection;
public IndustriesViewModel()
{
NewCollection = new ObservableCollection<IIndustries>();
_locationsIndustries = CommonLocator.ServiceLocator.Get<IIndustriesDao>().GetAll();
IndustriesCollections = new ObservableCollection<IIndustries>(_locationsIndustries);
}
private DelegateCommand _activeCommand;
public DelegateCommand RemoveCommand { get; set; }
public DelegateCommand ActiveCommand
{
get { return _activeCommand = new DelegateCommand(Active); }
}
private DelegateCommand InActiveCommand { get; set; }
private DelegateCommand AlleCommand { get; set; }
private void Active()
{
foreach (var active in CommonLocator.ServiceLocator.Get<IIndustriesDao>().GetAll().Where(x => x.IsActive == true))
{
NewCollection.Add(active);
}
IndustriesCollections = NewCollection;
}
Помогите разобраться, как мне правильно сделать ?
return _activeCommand = new DelegateCommand(Active);
А почему вы каждый раз пересоздаёте команду?DataContext
?public class DelegateCommand : DelegateCommand<object> { public DelegateCommand(Action executeMethod); public DelegateCommand(Action executeMethod, bool useCommandManager); public DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod, bool? useCommandManager = null); }