ComboBox Binding to display list but bind selection to entity? - silverlight-4.0

I am using a Silverlight 4 Navigation template. I use a DomainDataSource to load a specific entity called Issue. Each Issue has a Category. But I am not sure of the best way to perform the binding of a combobox so that the combobox is populated with the categories but the selected item is bound to the category of the Issue being edited. I have a method that seems like a total hack. So I would like some adice from the experts.

ComboBox has two different properties you can bind to, it has a ItemsSource, and a SelectedValue.
So in this case you could bind your list of categories tot he ItemsSource, and bind your category on your issue to SelectedValue.
Take a look here for more information:
http://johnpapa.net/silverlight/binding-to-silverlight-combobox-and-using-selectedvalue-selectedvaluepath-and-displaymemberpath/

Related

WinJS Binding List live sorting

I am using a WinJS.Binding.List to bind data to a ListView. I would like to use the createSorted method to create a sorted projection on the list. In addition, the data inside the list is live so it will be changing. Obviously the sorted projection will not automatically watch the properties to see if they are changing. I can't find a mechanism that will allow me to invoked a 're-sort'. Does something like that exist?
The list should automatically re-sort itself if you use the WinJS.Binding.mixin or WinJS.Binding.as on the elements in your list.
This will make them observable by the list and it should not only update any bound properties you reference in your itemTemplate but also re-sort the list when using projections.
http://msdn.microsoft.com/en-us/library/windows/apps/br211859.aspx
I believe you will need to call notifyMutated on the list at that item.
http://msdn.microsoft.com/en-us/library/windows/apps/hh700771.aspx

Localization in Silverlight, need multiple binding in XAML

We're trying to do some localization in our Silverlight app. Normal localization is no problem: we write the bindings in XAML and our textblock items show the correct text.
For items in datatemplates or for enums, we are experiencing some issues. We are binding a property (string) to the content of a button in the datatemplate. We have our 7 values shown on 7 buttons. But now we try to get those values from the dictionary (resx) and we cannot get a decent binding working. This is how we try now:
Content="{Binding Source={StaticResource ApplicationResources}, Path=?}"
At the question mark is where we used to place our static key: ItemType. But now we need to get the value from a collection bound to the parent (listbox) of the button.
Is there any syntax that can make this binding work?
We also doing something similar with enums binding to comboboxes. Any ideas on how we can get that localization to work?
Thanks in advance

How to get Control from DataTemplate and ControlTemplate ? thinks so much

When i define a control in DataTemplate, how to get reference of this control ?
If the control in ControlTemplate of Style , how to get ?
You should instead tell us why you would need to reference a control inside a template.
Consider that the control will be rendered multiple times, so getting a single reference does simply not make any sense.
The most common approach to this is to 'name' the element that you wish to locate via x:Name="MyElementName", you can then use the FindName method to locate the names element. If your DataTemplate is being used in an ItemsControl to render multiple copies of yoru XAML markup, then clearly there will be a number of elements that share this same name. For this reason, there is a concept known as XAML namescope, you should read up on this to understand the scope of the name you provide.
If you require a more generic method for searching for elements in the visual tree, try Linq-to-VisualTree, you can use it to query you UI, for example:
var itemsFluent = this.Descendants<TextBox>()
.Where(i => i.Ancestors().FirstOrDefault() is Grid);
The above query will find all TextBoxs that have a Grid as a direct parent.
Finally, if you can avoid doing any of this, by using databinding, or event bubbling then do so! it is much easier.

Binding a custom control in a pivot item to the current item in the pivot control's ItemsSource

I have a pivot control which is bound to a list through the ItemsSource attribute.
In the ItemTemplate I would like to place a custom control, in which I would like to bind controls to the current item in the pivot's list.
I'm looking for something around
<MyControl Item="{Binding <Something here>}" />
But am not sure what <something here> should be to point to the current item in the control's databound list?
Thanks
You could do one of two things (that immediately spring to mind):
Include the information you need in the object that your list item binds to. This is likely to be repetitive and probably difficult to manage, but I don't know the details of your data, so it's hard to say.
Use a proxy for the Pivot.SelectedItem property, which you add as a resource to the page and bind to the pivot's SelectedItem property. You can then reference that resource as you would any other resource to get at the selected item.
If you're not familiar with this proxy concept, then Dan Wahlin's post on the subject should help.
Maybe I'm misunderstanding, but if this control is going inside the PivotItem then isn't the path you are looking for just:
<MyControl Item="{Binding}" />
e.g. if using a TextBlock then you might use:
<TextBlock Text="{Binding}" />
and this would then use the ToString() of the current pivot item
Or if using a complicated user control you might use:
<MySpecialControl DataContext="{Binding}" />
Sorry if I've got this wrong!

How do I call DSOperationType.REMOVE to remove the selected record from a drop-down grid?

I am trying to delete the selected record from the drop-down grid.
In trying to do this, I've so far learned that DSOperationType.FETCH is called when the fetchData() method is called on ValuesManager class. So now I want to know what line should be executed for calling DSOperationType.REMOVE.
Or is there a better way to accomplish this task?
DSOperationType.REMOVE will be called only when removing data/row from list grid or tree grid. It can be triggered functionally by calling ListGrid.removeData(someData) or ListGrid.removeSelectedData();
But for ComboBox/SelectBox (DropDown) type item there is no functionality to remove data from list as it can only be selected from a list of data (while loading data for list FETCH operation will be called).
You can implement the functionlity indirectly by using Combobox/SelectItem with listgrid - (ex:http://www.smartclient.com/smartgwt/showcase/#dropdown_grid_combobox_category). In listgrid you can have remove data functionality. Also check other types of functionality that can be implemented with combobx http://www.smartclient.com/smartgwt/showcase/#multi_select_combobox_category