HI all,
I am using infragistics xamgrid with few predefined textcoumns. I have a button in the same screen when I click on the button I need to hide 2 columns in the xamgrid. I want to do it through it's viewmodel class
Can any one please provide me the resoution for my issue or any existing sample?
Thanks in advance.
I would like to mention that your ViewModels should NEVER derive from DependencyObect. NEVER!!!
Hi Krasimir,
Thanks for your reply. I did manage to do the same as you have mentioned but from the blog of Josh Smith by adding the resource at the code file of the xaml file.
When I try to put it in the xaml file like you asked me to do, the required action does not occur.
Wondering why? How does putting it in the cs file does the trick and putting it in the xaml file doesn't.
Cheers,
Anshuman
Hello Axc6580,
I have been looking into the code snippet that you have provided me with and the reason for the Binding to the Visibility property of the Fields to not fire, seems to be that the UnboundField does not have a DataContext. When the Binding’s Source property is not set, the source of the binding is the DataContext of the element. The fields does not derive from FrameworkElement and does not have DataContext and the source of the binding for the Visibility property, in the code snippet that you have provided is null. In order to bind the Visibility property of the fields, you can add your ViewModel in the Resources section of the Window and set the Source of the Binding as follows:
...... <Window.Resources> <vm:MainPageViewModel x:Key="ViewModel"/> </Window.Resources> ....... ....... <igDP:UnboundField Name="gridCustomerId" Label="ID" Binding="{Binding customerid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ShowCustomerIDColumn, Source={StaticResource ViewModel}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> .......
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
I have been trying the model which you have mentioned here but without a luck!
Here's what I did:
Adding Visiblility property for an unbound field -
<igDP:UnboundField Name="gridCustomerId" Label="ID" Binding="{Binding customerid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ShowCustomerIDColumn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
In my View Model, adding a proerty of Visibility type://ToShow CustomerID Column private Visibility showCustomerIDColumn; public Visibility ShowCustomerIDColumn { get { return showCustomerIDColumn; } set { showCustomerIDColumn=value; InvokePropertyChanged("ShowCustomerIDColumn"); } } Then in the command handler using the following code:if(ShowCustomerIDColumn == Visibility.Collapsed) ShowCustomerIDColumn = Visibility.Visible; else ShowCustomerIDColumn = Visibility.Collapsed; InvokePropertyChanged("ShowCustomerIDColumn"); In the constructor of the ViewModel, I'm setting the column to collapsed: ShowCustomerIDColumn = Visibility.Collapsed Please help!
In my View Model, adding a proerty of Visibility type:
//ToShow CustomerID Column private Visibility showCustomerIDColumn; public Visibility ShowCustomerIDColumn { get { return showCustomerIDColumn; } set { showCustomerIDColumn=value; InvokePropertyChanged("ShowCustomerIDColumn"); } }
Then in the command handler using the following code:if(ShowCustomerIDColumn == Visibility.Collapsed) ShowCustomerIDColumn = Visibility.Visible; else ShowCustomerIDColumn = Visibility.Collapsed; InvokePropertyChanged("ShowCustomerIDColumn"); In the constructor of the ViewModel, I'm setting the column to collapsed: ShowCustomerIDColumn = Visibility.Collapsed Please help!
Then in the command handler using the following code:
if(ShowCustomerIDColumn == Visibility.Collapsed) ShowCustomerIDColumn = Visibility.Visible; else ShowCustomerIDColumn = Visibility.Collapsed; InvokePropertyChanged("ShowCustomerIDColumn");
In the constructor of the ViewModel, I'm setting the column to collapsed:
ShowCustomerIDColumn = Visibility.Collapsed
Please help!
Hello,
Thank you for your feedback. I have been looking into the scenario that you have described and I can suggest modifying the approach I have suggested with my previous reply. Since the XamGrid is in a view (I assume it is an UserControl), you can bind the CommnadParameter of the Button to that view, using ElementName binding and use a converter, in which you can find the XamGrid and return its Columns collection. I have modified the sample application of my previous reply, in order to implement this approach.