Binding DynamicObject to a DataGrid with automatic column generation?

There is no uniform way to query dynamic properties, generally it’s expected that you know them ahead of time. With DynamicObject, implementers may override GetMemberNames and that generally gives you the properties, however it is really meant for debugging because there is no requirement that it provide all properties. Otherwise if it’s your own DynamicObject … Read more

MarkupExtension that uses a DataBinding value

Nevermind, I finally found out how the referenced code works and could come up with a solution. Here’s just a short explanation for the record. <TextBlock Text=”{t:Translate ‘import files’, {Binding FileCount}}”/> This requires a class TranslateExtension, inherited from MarkupExtension, with a constructor accepting two parameters, one String and one Binding. Store both values in the … Read more

WPF MenuItem.Command binding to ElementName results to System.Windows.Data Error: 4 : Cannot find source for binding with reference

You can’t bind using element name from a context menu. The link is broken between the context menu and its placement target. You can get around it using a couple of tricks though… Use RoutedUICommands with a command binding on the UserControl, then no binding is needed. Use the placement target binding on the context … Read more

Binding datagrid column width

Because DataGrid columns are abstract objects which do not appear in the logical or visual tree of your window. You cannot bind properties on them using ElementName (there will be no namescope which is needed for those bindings). You can try using Source and x:Reference instead, e.g. {Binding Source={x:Reference TextCol01}, Path=ActualWidth}

Setting DataContext within UserControl is affecting bindings in parent

The declaration of your control and the instantiation are basically manipulating the same object, all the properties that are set in the declaration are also set on every instance. So if the properties were “visible” so to speak: <UserControl x:Class=”MyControlLib.ParentControl” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ xmlns:ctrl=”clr-namespace:MyControlLib”> <ctrl:ChildControl x:Name=”ChildName” DataContext=”{Binding RelativeSource={RelativeSource Self}}” PropertyOnChild=”{Binding PropertyInParentContext}”/> </UserControl> This is why … Read more

Winforms : How to bind the Checkbox item of a CheckedListBox with databinding

According to Samich’s answer, Here is a full example, the binding source is an Object private void Form1_Load(object sender, EventArgs e) { List<randomClass> lst = new List<randomClass>(); lst.Add(new randomClass()); lst.Add(new randomClass()); lst.Add(new randomClass()); lst.Add(new randomClass()); lst.Add(new randomClass()); lst.Add(new randomClass()); ((ListBox)this.checkedListBox1).DataSource = lst; ((ListBox)this.checkedListBox1).DisplayMember = “Name”; ((ListBox)this.checkedListBox1).ValueMember = “IsChecked”; for (int i = 0; i < … Read more

Why does WPF databinding swallow exceptions?

Databinding errors are swallowed natively, but they are displayed in the OUTPUT dialog in the visual studio interface. If you wish to be notified (and have as much control over it as possible), then you can use Trace Sources. Bea Stollnitz provides a great writeup about this (and debuginng the bindings in general) here: http://www.beacosta.com/blog/?p=52 … Read more