Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ListView Name="MyListView">
- <ListView.View>
- <GridView>
- <GridViewColumn Header="Foo" DisplayMemberBinding="{Binding Foo}"/>
- <GridViewColumn Header="Bar" DisplayMemberBinding="{Binding Bar}"/>
- </GridView>
- </ListView.View>
- </ListView>
- var foobars = new ObservableCollection<Foobar>();
- foobars.Add(new Foobar { Foo = "Hello", Bar = "world" });
- MyListView.ItemsSource = foobars;
- var word = (string)(((ListViewItem)MyListView.Items[0]).SubItems[1]);
- var word = ((Foobar)MyListView.Items[0]).Bar;
- var columns = ((GridView) MyListView.View).Columns;
- var foobar = (Foobar)MyListView.Items[0];
- var result = (string)DataBinder.Eval(foobar, (Binding) columns[0].DisplayMemberBinding);
- public class DataBinder
- {
- private static readonly DependencyProperty BindingEvalProperty = DependencyProperty.RegisterAttached(
- "BindingEval",
- typeof(Object),
- typeof(DependencyObject),
- new UIPropertyMetadata(null));
- public static Object Eval(Object data, Binding binding)
- {
- var newbinding = new Binding {Path = binding.Path, Converter = binding.Converter, Source = data};
- var evalobj = new DependencyObject();
- BindingOperations.SetBinding(evalobj, BindingEvalProperty, newbinding);
- return evalobj.GetValue(BindingEvalProperty);
- }
- }
Add Comment
Please, Sign In to add comment