Take the 2-minute tour ×

inside TestEntryView.xaml.cs

public partial class TestEntryView : UserControl
    public ObservableCollection<TestFieldView> Fields {get;set;}

where TestFieldView is a UserControl.

<UserControl x:Class="STS2Editor.View.TestEntryView"
         d:DataContext="{Binding TestEntry, Source={StaticResource Sample}}">
<Grid Background="{DynamicResource ButtonNormalBorder}" TextElement.Foreground="{DynamicResource TextBrush}">
    <Border Background="{DynamicResource ControlBackgroundBrush}" BorderBrush="{DynamicResource ControlBackgroundBrush}" BorderThickness="4" CornerRadius="16">

        <Grid Margin="4" >
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            <ScrollViewer Background="{DynamicResource ControlBackgroundBrush}" Grid.IsSharedSizeScope="True" Grid.Row="1">
                <ItemsControl x:Name="fieldList" ItemsSource="{Binding Fields, ElementName=testEntryView}"/>

The binding is right, but when I snoop the visual tree my child items all consist of a border and content presenter, no child visuals.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

I can only recreate your situation if for some reason LoadComponent is not called on your UserControl (TestFieldView) and the Xaml is not parsed correctly. This happens in InitializeComponent (see for example http://stackoverflow.com/questions/245825/what-does-initializecomponent-do-and-how-does-it-work-wpf). Are you sure you call it in the contructor of the TestFieldView?

share|improve this answer
This actually was the case! There was an overload that failed to call it, I feel like a fool now! –  Firoso Sep 22 '10 at 22:42

Are you sure this is the binding is connecting up to the correct data? I much prefer the

{Binding Fields,RelativeSource={RelativeSource TemplatedParent}}

binding approach from within a user control, but it should work either way (as long as you are sure its binding it shouldn't matter (perhaps depending on how you create an instance of your control)

You don't seem to have a style or DataTemplate associated with your TestFieldView item or anything? Plus since you are using a ItemsControl you probably need to define the ItemsPaneltemplate as well.

<ItemsControl Grid.Row="1" ItemsSource="{Binding Fields}">
        <UniformGrid Rows="1" />
       <CheckBox Content="{Binding  Name}" IsChecked="{Binding  IsSelected}"/>

Not sure without getting ahold of your code and messing around with it till it works but its proably something around the Items Control, panel template, data template side of things.

Though if I am completely misunderstanding you could try replacing the ItemsControl with a ListView (as this should at least show you a list of class names) which would give you some sort of display then you can work from there.

share|improve this answer
oh maybe useful to you galasoft.ch/mydotnet/articles/article-2007041201.aspx –  PJUK Sep 21 '10 at 16:38

Is the "TestEntryView.Fields" property a DependencyProperty? Or does it at least raise a PropertyChanged event? It wasn't clear on the above example if it does. If it isn't a DP or doesn't raise the PropertyChanged event, try one or the other. That may be the solution.


To change it to a dependency property, do this:

public ObservableCollection<TestFieldView> Fields
    get { return (ObservableCollection<TestFieldView>)GetValue(FieldsProperty); }
    set { SetValue(FieldsProperty, value); }

public static readonly DependencyProperty FieldsProperty =
    DependencyProperty.Register("Fields", typeof(ObservableCollection<TestFieldView>), typeof(MainWindow),
    new UIPropertyMetadata(new ObservableCollection<TestFieldView>()));
share|improve this answer
public ObservableCollection<TestFieldView> Fields {get;set;} <-- explicitly listed in posting! –  Firoso Sep 22 '10 at 20:30
Yeah, I saw that. I'm asking if it's a DependencyProperty, or if it implements INotifyPropertyChanged. –  karmicpuppet Sep 22 '10 at 20:33
And if it's not, I'm saying that you should try making it a dependency property, or make it raise PropertyChanged notifications. –  karmicpuppet Sep 22 '10 at 20:34
Kharmic, a DP can't be implemented by an auto property... –  Firoso Sep 22 '10 at 21:23
Firoso, I know that. But I thought that maybe you're just abbreviating your code above (it happens here at StackOverflow), which is why I verified. But anyway, I did make a suggestion. If it works for you, great. If it doesn't, sorry about that. (Easy on the downvotes, and the exclamation marks though. I'm just trying to help). Cheers! –  karmicpuppet Sep 22 '10 at 22:23

Your Answer


