Here's a link to a sample project that illustrates the problem I'm having: https://dl.dropbox.com/u/109257/RadControlsSilverlightApp1.zip
I'm trying to create a custom column for the RadGridView that contains a TextBlock and RadButton when not in edit mode and a control called LookupControl which contains a TextBox and RadButton, but I am having some issue with the binding, and I'm not sure where I have gone wrong. My grid is populated with dynamic data using the method and classes found here: http://blogs.telerik.com/vladimirenchev/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx
In the sample project you will see in DetailGrid.xaml.cs see:
where for one column I am adding my custom LookupColumn. In the LookupColumn class you will see that when a cell enters edit mode I create an instance of the LookupControl, binding the dataItem to the TextProperty dependency property which binds to LookupControl.MyText. Process shown below:
The MyText property of the LookupControl is bound to the Text property of the child TextBox.
Now that I've layed out how I have things set up, the problem I'm having is that when you run the program and put Column4 in edit mode, type in a value and tab off the control, the value displays properly in non-edit mode. However, if you type a value into the TextBox of Column4 and click off of it the value does not display properly, but if you click back in the cell, and again click off of it it does start displaying the value correctly. It also appears that when the value displays incorrectly the underlying dataItem and collection are not being updated.
I've narrowed down the issue to that fact that for some reason the way I have my binding setup isn't working 100% correctly. In MyDataRow the set portion of the following function
never gets hit in the debugger no matter how you manipulate the data in the custom column, which I guess means the PropertyChanged event never gets fired, which probably has something to do with the inconsistencies I'm seeing. On the otherhand, the non-custom, standard columns always fire the setter, thus firing the PropertyChanged event, and I'm having no problems with them.
Is there something I have configured wrong? Is this not expected functionality? I'm at a loss at the moment and would appreciate any help you can offer. Let me know if I need to clarify anything.
Thanks.
I'm trying to create a custom column for the RadGridView that contains a TextBlock and RadButton when not in edit mode and a control called LookupControl which contains a TextBox and RadButton, but I am having some issue with the binding, and I'm not sure where I have gone wrong. My grid is populated with dynamic data using the method and classes found here: http://blogs.telerik.com/vladimirenchev/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx
In the sample project you will see in DetailGrid.xaml.cs see:
private
void
RadGridView1_AutoGeneratingColumn(
object
sender, GridViewAutoGeneratingColumnEventArgs e)
{
if
(e.Column.UniqueName ==
"Column4"
)
{
e.Cancel =
true
;
LookupColumn column =
new
LookupColumn()
{
DataMemberBinding =
new
Binding(
"Data["
+ e.Column.UniqueName +
"]"
)
{
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
},
Header = e.Column.UniqueName
};
((RadGridView)sender).Columns.Add(column);
}
}
where for one column I am adding my custom LookupColumn. In the LookupColumn class you will see that when a cell enters edit mode I create an instance of the LookupControl, binding the dataItem to the TextProperty dependency property which binds to LookupControl.MyText. Process shown below:
public
override
FrameworkElement CreateCellEditElement(GridViewCell cell,
object
dataItem)
{
this
.BindingTarget = LookupControl.TextProperty;
var picker =
new
LookupControl();
picker.SetBinding(LookupControl.TextProperty,
new
Binding()
{
Mode = BindingMode.TwoWay,
NotifyOnValidationError =
true
,
ValidatesOnExceptions =
true
,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
Source = dataItem,
Path =
new
PropertyPath(
this
.DataMemberBinding.Path.Path)
});
return
picker;
}
The MyText property of the LookupControl is bound to the Text property of the child TextBox.
Now that I've layed out how I have things set up, the problem I'm having is that when you run the program and put Column4 in edit mode, type in a value and tab off the control, the value displays properly in non-edit mode. However, if you type a value into the TextBox of Column4 and click off of it the value does not display properly, but if you click back in the cell, and again click off of it it does start displaying the value correctly. It also appears that when the value displays incorrectly the underlying dataItem and collection are not being updated.
I've narrowed down the issue to that fact that for some reason the way I have my binding setup isn't working 100% correctly. In MyDataRow the set portion of the following function
public
object
this
[
string
columnName]
{
get
{
if
(data.ContainsKey(columnName))
{
return
data[columnName];
}
return
null
;
}
set
{
if
(!data.ContainsKey(columnName))
{
data.Add(columnName, value);
OnPropertyChanged(columnName);
}
else
{
if
(data[columnName] != value)
{
data[columnName] = value;
OnPropertyChanged(columnName);
}
}
}
}
never gets hit in the debugger no matter how you manipulate the data in the custom column, which I guess means the PropertyChanged event never gets fired, which probably has something to do with the inconsistencies I'm seeing. On the otherhand, the non-custom, standard columns always fire the setter, thus firing the PropertyChanged event, and I'm having no problems with them.
Is there something I have configured wrong? Is this not expected functionality? I'm at a loss at the moment and would appreciate any help you can offer. Let me know if I need to clarify anything.
Thanks.