I have a View ConfigRole which contains DataGrid with two Columns: View and IsEnabled(CheckBox), and a Search area.
and the Button Save it works correctly, I make all views which I want IsEnabled and I save it : for exemple:
And when I use the search box, I have the correct result for all the views I search on it,for exemple I write 'Customer' in search box ,I have all the views with the key 'Customer':
My problem is when I make Save Button after Search ,all the CheckBox (IsEnabled in the first View will be FALSE !! just the Views I make it Enabled in the Search view are Save !
XAML ConfigRole:
- <TextBox x:Name="textBox" Text="{Binding ViewName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
- NotifyOnValidationError=True ,TargetNullValue=''}" />
-
- <DataGrid x:Name="dataGrid" SelectedItem="{Binding SelectedView}" ItemsSource="{Binding ViewList}"
- CanUserAddRows="False" AlternationCount="2" AlternatingRowBackground="Blue" AutoGenerateColumns="False" >
-
- <DataGrid.Columns>
- <DataGridTextColumn Header="View" Binding="{Binding ViewCode}" IsReadOnly="True" />
-
- <DataGridTemplateColumn Header="Is Enabled" Width="Auto">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
- </DataTemplate>
- </DataGridTemplateColumn.CellTemplate>
- </DataGridTemplateColumn>
- </DataGrid.Columns>
-
- </DataGrid>
- lt;Button Command="{Binding SaveRole}" Visibility="{Binding Path=ShowSaveButton, Converter={StaticResource BoolToVis}}" CommandParameter="{Binding ElementName=ConfigureRole}"/>
-
- </Grid>
ConfigRoleViewModel:
- private ObservableCollection<ViewRoleMapClass> _viewList;
- private MiniTasServicesClient WCFclient = new MiniTasServicesClient();
- public int test;
-
- public ConfigRoleModel(int RoleId,ObservableCollection<UserRoleClass> roleList)
- {
- test = RoleId;
- _viewList = new ObservableCollection<ViewRoleMapClass>(WCFclient.getViewRoleMapsByRole(RoleId));
- saveRole = new RelayCommand<Window>(configRole);
- }
-
- private RelayCommand<Window> saveRole;
- public RelayCommand<Window> SaveRole
- {
- get { return saveRole; }
- }
-
-
-
- public ObservableCollection<ViewRoleMapClass> ViewList
- {
- get { return _viewList; }
- set
- {
- _viewList = value;
- OnPropertyChanged("ViewList");
- }
- }
-
-
- private void configRole(Window window)
- {
- List<ViewRoleMapClass> listViewRoleMap = new List<ViewRoleMapClass>();
- foreach (ViewRoleMapClass view in ViewList)
- {
- if (view.IsEnabled) listViewRoleMap.Add(view);
- }
- int resultUpdate = WCFclient.updateViewRoleMap(listViewRoleMap, test);
- if (resultUpdate == 0)
- {
- string sCaption = "Save notification";
- string sInformation = "Save operation is performed successfully";
- MessageBoxButton btnMessageBox = MessageBoxButton.OK;
- MessageBoxImage icnMessageBox = MessageBoxImage.Information;
-
- MessageBoxResult rsltMessageBox = MessageBox.Show(sInformation, sCaption, btnMessageBox, icnMessageBox);
- }
- _refreshList();
- }
-
-
- private string _viewName;
- public string ViewName
- {
- get { return _viewName; }
- set
- {
- _viewName = value;
- OnPropertyChanged("ViewName");
- _viewList = searchByCriteria(ViewName);
- OnPropertyChanged("ViewList");
- }
- }
- private ObservableCollection<ViewRoleMapClass> searchByCriteria(string _viewName)
- {
- List<ViewRoleMapClass> resultSearch=new List<ViewRoleMapClass>();
- _viewList = new ObservableCollection<ViewRoleMapClass>(WCFclient.getViewRoleMapsByRole(test));
-
- if (_viewName != null)
- {
- resultSearch = _viewList.Where(c => c.ViewCode.ToLower().Contains(_viewName.ToLower())).ToList();
- }
- return new ObservableCollection<ViewRoleMapClass>(resultSearch);
- }
How can I fix it?
Thanks,