datarowview binding to combobox datatemplate - wpf

I have a wpf application using mvvm. I am trying to bind my datatable to a combobox that has a datatemplate of 2 textblocks. How do I specify the binding on these text blocks to bind to datarowview.item["columnname"]
In short, what I am trying to achieve is to bind 2 columns of my datatable to a multicolumn combo box

It turns our that you can simply bind to the column names just like how you blind to an object's public property. WPF is smart enough to figure it out.

Related

Hosting a WF TextBox in a WPF DataGrid

I am making a WPF application in vb.net
I currently have a DataGrid that has a DataTable source attached to it to retrieve values from.
The DataGrid has its columns defined in my vb code. The DataTable itself is updated in the vb code as well.
I was able to figure out how to define DataGridTextColumns/DataGridTemplateColumns to bind a DatePicker and Image to my Datagrid.
However, now I would like to bind a Windows Form Textbox as well.
I am able to use WindowsFormHost inside the XAML to create a WF TextBox, but I can't figure out how to bind this TextBox to my DataGrid. The TextBox has no Binding option, and I can't set the text={Binding name} either.
I noticed there is a BindingContext for the WF TextBox. Should I use this? If so, how do I do that?
Thank you in advance!

Any ideas how to implement ComboBox to represent hierarchical data?

Does anybody saw control like this somewhere?
I need to make such control to represent hierarchical data (it should be generic very likely, i.e. data binding, templates support).
Something like combination of ComboBox and MenuItem’s.
I think I will redefine the combobox itemtemplate with some hierarchicaldatatemplate along with popup class.
Just put ComboBoxes on a form and bind the ItemsSource to the top level collection.
Then bind the DataContext of the next ComboBox to the SelectedItem of the box on the left and bind its ItemSource to the collection of items.
You know how to bind to SelectedItem?
E.G.
Column1
Public String Name
Public List Column2s
So you bind the first combox to List with he displaymemberpath = name
Then on the second combobox you bind to Column1 selecteditem with items source path of Column2s
The trick is to build up the Lists within the Lists within the Lists
All right, I made it by custom control inherited from ComboBox, custom ComboBoxItem inherited from HeaderedItemsControl and using HierarchicalDataTemplate.

WPF control with many GridViews

I have a WPF user control that will dynamically have any number of GridViews. Each is essentially the exact same except for the ItemsSource. Therefore each have the same columns and the same RowDetailsTemplate. To be specific what I am actually doing is settings the columns to the bound values and then setting the RowDetailsTemplate to the data template.
What is the best approach to essentially define the GridView once and copy it to all the others. I have tried XamlWriter.Save with the GridView in the resources, but the columns and RowDetailsTemplate are not saved. I have also tried a style, but the columns property is not settable.
Maybe I did something wrong with the two approaches.
Use an ItemsControl with ItemTemplate. The DataTemplate used for the Itemtemplate should contain the GridView XAML with all the column definitions. Next bind the ItemsControl's ItemSource to a collection of whatever data object you want the GridViews to use as ItemSource.

Get textbox binding in wpf datagridtemplatecolumn

I have a wpf datagrid containing multiple datagridtemplatecolumns, which all are build up from a datatemplate which contains a textbox.
Now I want to get the binding of the textbox (I have a reference to the template column which textbox's binding I woukld like to determine).
Alternatively it would be nice to return the X:Name of the template column
Any hints?
Regards
klaus
Use VisualTreeHelper to travers the grid and find all text boxes (e.g. by name) and then use GetBindingExpression to get the bindig: control.GetBindingExpression(control.TextProperty)

Silverlight 3.0: How to bind DataGridColumn to an ICommand wherein the DataGrid is bound to an ItemsSource

I have a SL3 DataGrid bound to a collection. One column of the datagrid is a HyperlinkButton column and I want to bind the click event of the column to an ICommand present in the VM.
pseudo code:
DataGrid ItemsSource="{Binding someCollection}"
DataGridHyperLinkColumn Commands.Command="{Binding myClickCommand}"
Now in this scenario the Commands.Command is trying to locate the myClickCommand within the someCollection instead of getting it from the VM myClickCommand property.
I have also tried the fix Commands.Command="{Binding Path=DataContext.myClickCommand, ElementName=nameOfUserControl}" but that fails as well.
What is the way out...? I don't want to use BindingHelper since SL3 already supports ElementBinding...
voila...there is a solution already available from Dan Wahlin out here: http://weblogs.asp.net/dwahlin/archive/2009/08/20/creating-a-silverlight-datacontext-proxy-to-simplify-data-binding-in-nested-controls.aspx

Resources