Hello experts,
i'm trying to bind IsReadOnly property on xamgrid to a boolean property on my datacontext(ViemModel).
and for some odd reason it wont bind.
i want to block and unblock the columns the editing dynamically
here is a snipet of my ViewModel
private
bool m_isReadOnly = true;
{
get { return m_isReadOnly; }
set{m_isReadOnly = value;
RaisePropertyChanged("IsReadOnly");
}
and in the xaml i do the next binding
<
ig:TextColumn HeaderText="Pressure [m]" Key="Pressure"
IsSummable="False"
IsFixable="False"
IsReadOnly="{Binding Path=IsReadOnly}">
the column can see the properties of my VM but isreadonly wont work when i change the property true/false while running.
any ideas?
Hello,
I am checking if this is still an issue for you.
If you require any further assistance please do not hesitate to ask.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics
www.infragistics.com/support
Thanks for the fast replay!
i want to use dependency object to bind the readonly property on the xamgrid,
could u please make a simple example on how to do that? both in the code and in xaml, i dont fully understand the example in the link.
thanks in advance!
To be more precise, how do i get the instance of the DataContextProxyClass in my ViewModel to change the boolean property.
i could make the boolean field static, but i will have problems with the property changed event.
thank you
I have been looking into your question and according to the given sample DataContextProxyClass in not intend to be set in the code behind, because the example tries to demonstrate a different technique. Nevertheless if you would like to get this instance you can use LayoutRoot.FindResource["proxy"] method.
What is happening is that you have declared the DataContextProxy class that exposes the ProxiedObject property:
public class DataContextProxy : DependencyObject
public object ProxiedObject
get { return (object)GetValue(ProxiedObjectProperty); }
set { SetValue(ProxiedObjectProperty, value); }
public static readonly DependencyProperty ProxiedObjectProperty =
DependencyProperty.Register("ProxiedObject", typeof(object),
typeof(DataContextProxy), null);
In the xaml we are trying to bind a non-visual element to some property in the code behind and because it is not possible, we are going to use the ProxiedObject dependency property . Lets say that you have ViewModel class that exposes a property called MyCustomHeader. If you set :
<Grid x:Name="LayoutRoot" DataContext="{StaticResource vm}">
And then bind the ProxiedObject property to the grid’s DataContext:
<Grid x:Name="LayoutRoot" … >
<Grid.Resources>
<local:DataContextProxy
ProxiedObject="{Binding Path=DataContext,ElementName=LayoutRoot}"
x:Key="proxy" />
</Grid.Resources>
the ProxiedObject property will actually hold reference of our VeiwModel class. All we have to do then is to bind the needed xamGrid’s property to the corresponding property of that instance:
<ig:TextColumn Key="CustomerName"
HeaderText="{Binding Source={StaticResource proxy},
Path=MyCustomHeader }" />
I hope that the approach seems more clear now.
Please in case of other questions regarding the discussed matter, do not hesitate to ask again.
Infragistics, Inc.
Thank you again for the explanation!
i still cant make it work,my text column cant see the viewmodel property, i did it step by step. the only difference is, i use Locator class from laurent bugnion mvvm light toolkit to get the registered view model. and my layoutroot is a stack panel and not a grid.
the datacontext of the stackpanel is DataContext="{Binding MyViewModel, Source{StaticResource Locator}} "
under this i made proxy resource just like in the example.
in MyViewModel i have boolean property "IsReadOnly"
and in my TextColumn i did the next binding
IsReadOnly="{Binding Source{StaticResource proxy}, Path=IsReadOnly}"
but i get "cannot resolve symbol" from Path=IsReadOnly and when i run it, it wont bind.
any idea what i'm doing wrong?
Would you please send me an isolated sample in order for me to take a look.
Thank you in advance.
Hello Vamshi,
I can say that this behavior is expected and you have to clear the cache. You can do it by code, too. Here is discussed how to do so:
http://stackoverflow.com/questions/12423088/programmatically-clear-silverlight-application-storage
Hi Ekaterina,
I have solved the visibility problem.There was some binding problem my side. But the point is like everytime before i launch my application, i need to clear the cache files. Otherwise it is not working properly. I think as we are storing the grid properties in IsolatedStorageFile, whenever i launch the application without clearing the cache, it is taking the last visibility stage.Is there any other solution ,other than clearing the cache.
Can you please help me in resolving the problem.
I have same problem like hiding the xamgrid columns based on the search criteria. I am not able to open the project which you have shared. I am using VS2010.
I am following the same approach using the proxied object, but the visibility property is not working.
Could you please help me in resolving the problem and share your sample project.
Thanks
G VamshiKrishna
Great thanks for the help!
I have been looking into your issue and I have created a sample project that demonstrates the complete implementation of this approach. Notice that the Proxy class is working as expected and the property is being applied successfully.
Please let me know if you have future concerns regarding the discussed matter.
Infragistics, Inc .