It does indeed, here is the code for the property, it's from the auto-generated file:
[DataMember()]
public Guid CompanyID
{
get
{
return this._companyID;
}
set
{
if ((this._companyID != value))
{
this.ValidateProperty("CompanyID", value);
this.RaiseDataMemberChanging("CompanyID");
this._companyID = value;
this.RaiseDataMemberChanged("CompanyID");
}
}
}
I wrote a small routine to find the combo in the dataform by inspecting the VisualTree and I can see that the IsEnabled property is set to false on the Combo:
I tried to find what was bound to the property using GetBindingExpression(Control.IsEnabledProperty) but it returns null...
If you look in the source code for the DataFormComboBoxField, using.net reflector, you can see, that IsEnabled is set when the combo box is constructed:
So, I think for some reason the data form field thinks that the property is read-only. Exactly why this happens, I'd have to substantially more investigation, but I do wonder whether it has to do with the use of a converter?
I've had the exact same problem as you and it's been driving me up the wall for a whole week now. Then today I stumbled across the answer: the DataFormComboBox gets disabled when it is bound to a property of type System.Guid. I think the is a pretty fundamental
bug as we use Guids allmost exclusively as foreign keys in our databses.
Luckily I've also found an easy way around this problem: you can define an additional property in a partial class (in the Silverlight project if you're using RIA Services) to accompany your Entity.
For the parent entity this could look something like this:
namespace MyProject.Web
{
public sealed partial class Customer
{
public string StringCustomerID
{
get { return this.CustomerID != null ? this.CustomerID.ToString() : null; }
}
}
}
For the child entity you will need to add a setter aswell:
namespace MyProject.Web
{
public sealed partial class Order
{
public string StringUserID
{
get { return this.UserID != null ? this.UserID.ToString() : null; }
set { this.UserID = value != null ? new Guid(value): Guid.Empty; }
}
}
}
This fixed it for me, so I hope it will do the same for you.
I come across the same problem too, except mine is binded to an entity with a string as FK behind it. I would thought this be a very typical use case for any type table attribute. The code looks up the type table for a list of possible collection and the
UI display them in a combo box.
The dataForm is binded to Assessment entity, Assessment Type is one of its property. I bind the comboBox ItemsSource in code behind because I cant figure out how to do this in the xaml itself.
[
Association("AssessmentType_Assessment",
"AssesmentTypeID",
"AssessmentTypeID", IsForeignKey=true)]
[Bindable(true,
BindingDirection.TwoWay)]
public
AssessmentType AssessmentType
When you change the AssessmentTypeID which is definded in the association on the entity, the related entity will automatically change along with it, so you do not need to bind the entity itself.
Upto now I have found no other way than to set the itemsource on the combobox in code, at least no other way that works ;) The problem is that the load of entities is asynchronous and the refresh of listitems is not automatic, so you need to handle the loaded
event on the context in order to fill the dropdown list.
Another thing I've found is that when you change the partent entity in thes way other controls in the app don't seem to get notified of this, so if you have another control displaying for instance the details of your selected AssessmentType entity, you will
need to update them yourself (for instance by resetting the itemsource)
pyt
Member
35 Points
17 Posts
DataFormComboBoxField grayed out
May 12, 2009 11:03 PM | LINK
I'm having problems getting the DataFormComboBoxField control to work in my form.
I cannot figure out why the drop-down is always disabled.
Here is the xaml:
The CompanyID property is a Guid. The dataform is in AutoEdit.
I assign a list of companies to the drop down's ItemsSource in the UserControl constructor.
What am I missing?
Thanks,
Pierre-Yves Troel
Ayuda Media Systems
Ayuda Media Systems
http://www.ayudasystems.com
StefanOlson
Member
260 Points
138 Posts
Re: DataFormComboBoxField grayed out
May 13, 2009 01:02 AM | LINK
I presume that the CompanyID property has a publicly accessible setter? Are there any metadata attributes on the CompanyID property?
...Stefan
pyt
Member
35 Points
17 Posts
Re: DataFormComboBoxField grayed out
May 13, 2009 01:57 PM | LINK
It does indeed, here is the code for the property, it's from the auto-generated file:
[DataMember()] public Guid CompanyID { get { return this._companyID; } set { if ((this._companyID != value)) { this.ValidateProperty("CompanyID", value); this.RaiseDataMemberChanging("CompanyID"); this._companyID = value; this.RaiseDataMemberChanged("CompanyID"); } } }I wrote a small routine to find the combo in the dataform by inspecting the VisualTree and I can see that the IsEnabled property is set to false on the Combo:
I tried to find what was bound to the property using GetBindingExpression(Control.IsEnabledProperty) but it returns null...
Pierre-Yves Troel
Ayuda Media Systems
http://www.ayudasystems.com
Ayuda Media Systems
http://www.ayudasystems.com
StefanOlson
Member
260 Points
138 Posts
Re: DataFormComboBoxField grayed out
May 15, 2009 12:48 AM | LINK
If you look in the source code for the DataFormComboBoxField, using.net reflector, you can see, that IsEnabled is set when the combo box is constructed:
private ComboBox GenerateComboBox(bool isReadOnly) {ComboBox box =
new ComboBox {IsEnabled = !isReadOnly};isReadOnly comes from these functions:
internal virtual bool EffectiveIsEditModeReadOnly { get; } internal virtual bool EffectiveIsReadOnly { get; }So, I think for some reason the data form field thinks that the property is read-only. Exactly why this happens, I'd have to substantially more investigation, but I do wonder whether it has to do with the use of a converter?
...Stefan
NickVerschueren
Member
16 Points
8 Posts
Re: DataFormComboBoxField grayed out
May 16, 2009 09:03 PM | LINK
Hi Pierre-Yves,
I've had the exact same problem as you and it's been driving me up the wall for a whole week now. Then today I stumbled across the answer: the DataFormComboBox gets disabled when it is bound to a property of type System.Guid. I think the is a pretty fundamental bug as we use Guids allmost exclusively as foreign keys in our databses.
Luckily I've also found an easy way around this problem: you can define an additional property in a partial class (in the Silverlight project if you're using RIA Services) to accompany your Entity.
For the parent entity this could look something like this:For the child entity you will need to add a setter aswell:
This fixed it for me, so I hope it will do the same for you.
Nick Verschueren - Euricom
.Net RIA Services silverlight RIA RIA Services LINQ - Entities Ria Services databinding .NET RIA Services shared silverlight
Nick Verschueren - Euricom
pyt
Member
35 Points
17 Posts
Re: DataFormComboBoxField grayed out
May 16, 2009 10:18 PM | LINK
Thanks a lot for the workaround, hopefully this will get fixed in the release.
Ayuda Media Systems
http://www.ayudasystems.com
glasin
Member
9 Points
8 Posts
Re: DataFormComboBoxField grayed out
May 19, 2009 06:30 AM | LINK
I come across the same problem too, except mine is binded to an entity with a string as FK behind it. I would thought this be a very typical use case for any type table attribute. The code looks up the type table for a list of possible collection and the UI display them in a combo box.
The dataForm is binded to Assessment entity, Assessment Type is one of its property. I bind the comboBox ItemsSource in code behind because I cant figure out how to do this in the xaml itself.[
Association("AssessmentType_Assessment", "AssesmentTypeID", "AssessmentTypeID", IsForeignKey=true)] [Bindable(true, BindingDirection.TwoWay)] public AssessmentType AssessmentType<
df:DataFormComboBoxField Binding="{Binding AssessmentType, Mode=TwoWay, Converter={StaticResource assessmentTypeConverter}}" />assessmentTypeField.ItemsSource = myGradeBookContext.AssessmentTypes.Select(a => a.AssessmentTypeID);
NickVerschueren
Member
16 Points
8 Posts
Re: DataFormComboBoxField grayed out
May 19, 2009 10:39 AM | LINK
The issue here is that in the binding you're specifying the entity rather than the foreign key field. You shoud change the binding to:
Binding="{Binding AssessmentTypeID, Mode=TwoWay, Converter={StaticResource assessmentTypeConverter}}" />
When you change the AssessmentTypeID which is definded in the association on the entity, the related entity will automatically change along with it, so you do not need to bind the entity itself.
Upto now I have found no other way than to set the itemsource on the combobox in code, at least no other way that works ;) The problem is that the load of entities is asynchronous and the refresh of listitems is not automatic, so you need to handle the loaded event on the context in order to fill the dropdown list.
Another thing I've found is that when you change the partent entity in thes way other controls in the app don't seem to get notified of this, so if you have another control displaying for instance the details of your selected AssessmentType entity, you will need to update them yourself (for instance by resetting the itemsource)
Nick Verschueren - Euricom
RogerGu
Participant
1124 Points
420 Posts
Re: DataFormComboBoxField grayed out
Jun 02, 2009 11:15 PM | LINK
Can I ask you two to share how you are setting the ItemssSource for the DataFormComboBoxField?
Thanks,
DataFormComboBoxField ItemsSource
Twitter
davidezordan
Contributor
6294 Points
957 Posts
Re: Re: DataFormComboBoxField grayed out
Jun 03, 2009 09:51 PM | LINK
@Roger: I've replied here http://silverlight.net/forums/p/94171/218171.aspx#218171
Silverlight MVP
Blog Twitter Silverlight Experts