Databinding and Value Converter questions
-
OKAY -- I've done a ton of searching and I've not found anything that can directly help me with what I need to do. I'm building a business application with Silverlight 3.0 and I'm down to my VERY LAST issue! I have 3 ComboBox controls (building, datacenter, locationType) where datacenter has a dependancy on building. I have a listbox with customers (works great). When a customer is selected, a list of existing locations is populated. (works great) For these (and other) populated controls, I put out a message "loading...blah blah blah" then when the data comes back I display "data loaded...blah blah blah" which works great. I've got my datacenter dependancy working great as well. Pick a building and the correct set of datacenters is loaded. My editor fields are wrapped in a grid and a datasource for my location object was created. I populate it in my code by setting editorContainer.DataContext = selectedCustomerLocation; editorContainer is the grid that wraps all of my editor controls. Each control that edits the fields of the control is bound to the datacontext of the grid, but Expression does not seem to place the parent object name as a fully-qualified name. (example my xaml says 'BuildingNumber' instead of CustomerLocation.BuildingNumber) I expected the editor controls to self populate with the data once DataContext was set. (doesn't work) I also want each combobox to display the correct selected item. I know I need to say SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter= ....". I also expected that in the Convert logic I perform the linq to lookup the building enumerated object and return the text value for the integer returned in the customer location object. Not quite sure how to explicitely pass to the converter the value of the building ID (for example) AND the list of building name/values to have it return the correct text. So this is the first question which is the syntax to pass parameters into the converter? The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template??? Any help at all would be great. I found a ton of examples but all of them are either too simplistic (working with internal collections statically created and never dealing with an externally selected object to bind with) or buried within the context of a
-
OKAY -- I've done a ton of searching and I've not found anything that can directly help me with what I need to do. I'm building a business application with Silverlight 3.0 and I'm down to my VERY LAST issue! I have 3 ComboBox controls (building, datacenter, locationType) where datacenter has a dependancy on building. I have a listbox with customers (works great). When a customer is selected, a list of existing locations is populated. (works great) For these (and other) populated controls, I put out a message "loading...blah blah blah" then when the data comes back I display "data loaded...blah blah blah" which works great. I've got my datacenter dependancy working great as well. Pick a building and the correct set of datacenters is loaded. My editor fields are wrapped in a grid and a datasource for my location object was created. I populate it in my code by setting editorContainer.DataContext = selectedCustomerLocation; editorContainer is the grid that wraps all of my editor controls. Each control that edits the fields of the control is bound to the datacontext of the grid, but Expression does not seem to place the parent object name as a fully-qualified name. (example my xaml says 'BuildingNumber' instead of CustomerLocation.BuildingNumber) I expected the editor controls to self populate with the data once DataContext was set. (doesn't work) I also want each combobox to display the correct selected item. I know I need to say SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter= ....". I also expected that in the Convert logic I perform the linq to lookup the building enumerated object and return the text value for the integer returned in the customer location object. Not quite sure how to explicitely pass to the converter the value of the building ID (for example) AND the list of building name/values to have it return the correct text. So this is the first question which is the syntax to pass parameters into the converter? The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template??? Any help at all would be great. I found a ton of examples but all of them are either too simplistic (working with internal collections statically created and never dealing with an externally selected object to bind with) or buried within the context of a
Michael Eber wrote:
SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter=
A trick I used to pass multple values (my entire collection) to the converter was to not bind to the field name. Try this - SelectedText = "{Binding Converter=myValueConverter, ConverterParameter= ....".
Michael Eber wrote:
The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template???
Not quite sure I understand your question. However, IMO, the datacontext looks fine. DataTemplates are used to specify the visual structure of a data object, so DataContexts and DataTemplates are actually two different things (used differently).
There are only 10 types of people in this world — those who understand binary, and those who don't.
-
Michael Eber wrote:
SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter=
A trick I used to pass multple values (my entire collection) to the converter was to not bind to the field name. Try this - SelectedText = "{Binding Converter=myValueConverter, ConverterParameter= ....".
Michael Eber wrote:
The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template???
Not quite sure I understand your question. However, IMO, the datacontext looks fine. DataTemplates are used to specify the visual structure of a data object, so DataContexts and DataTemplates are actually two different things (used differently).
There are only 10 types of people in this world — those who understand binary, and those who don't.
What I mean as far as passing data to the converter is this: I need to pass the collection of objects that populate the dropdown box. I also need to pass the value set by the object. I've seen a setup like this for passing a date: ConvertParameter=0\d\ But I have no idea what that means or how they are actually passing the date field.
-
What I mean as far as passing data to the converter is this: I need to pass the collection of objects that populate the dropdown box. I also need to pass the value set by the object. I've seen a setup like this for passing a date: ConvertParameter=0\d\ But I have no idea what that means or how they are actually passing the date field.
Michael Eber wrote:
ConvertParameter=0\d
AFAIK, ConvertParameter does not support binding. So, you can only pass 'hardcoded' values like 0\d, which will format your date. The date is passed using the binding value
e.g. Text="{Binding myDate, Converter={StaticResource myConverter}}"
. However, the entire collection can be passed into the converter. The appropriate value(s) can then be used inside the converter to construct the value you want to display in your UI.There are only 10 types of people in this world — those who understand binary, and those who don't.