WPF: Bindings Added to Users Impacted by UserControl Users
I have a custom control that allows you to add items to it by exposing the Grid Children property. Any control I add displays fine, but when I try to bind the property of the added item to a control in the main window, nothing happens (example):
<TextBox Name="txtTest" Text="Success!" />
<mycontrols:CustomUserControl.ExposedGridChildren>
<TextBox Text="{Binding ElementName=txtTest, Path=Text, FallbackValue=fail}"/>
</mycontrols:CustomUserControl.ExposedGridChildren>
This example always causes the TextBox to show "fail". This is how I show the child elements in the custom control:
public UIElementCollection ExposedGridChildren
{
get { return grdContainer.Children; }
}
Any thoughts? Is this a question of scale? I know I cannot name the elements that I am adding to the children due to scope errors. Thanks Brian.
a source to share
This might answer your question: How do you bind the children of the grid to the list?
Or, as the WPF doctor says: ( http://drwpf.com/blog/2007/10/15/itemscontrol-a-is-for-abundance/ )
Is the panel an ItemsControl?
No. The logical children of a panel are UIElements, while the logical children of a control (its Elements) can be any CLR objects.
Sidebar: So what is a sidebar? The main role of the panel is to provide the layout with support for its children. Although a panel supports a collection of children, it is not technically a WPF "control" ... That is, it is not derived from the base Control class and it does not support the WPF templated concept. Instead, it is a single element with a single purpose ... namely, to size and position (aka, measure and arrange) its children.
a source to share