Take the 2-minute tour ×

I think I'm missing something that should be obvious here, but I'm drawing a blank on this one.

I've built a very primitive UserControl containing nothing more than a TextBox to use as a log window:

<UserControl x:Class="My.LoggerControl"
    <Grid x:Name="LayoutRoot">
        <TextBox x:Name="LogWindow" AcceptsReturn="True"/>

I don't expect that to be the best way to do it, but it should be good enough for a prototype.

The code-behind is similarly simple:

public partial class LoggerControl : UserControl, ILogger
    public LoggerControl()

    private LogLevel level = LogLevel.Warning;

    #region ILogger

    public LogLevel Level
        get { return level; }
        set { level = value; }

    public void OnError(string s)
        if (level >= LogLevel.Error)
            LogWindow.AppendText("ERROR:::" + s + "\n");

    // ...

The thing I can't figure out is how to add this control to my MainWindow.xaml. Simplifying, lets say my window looks like this:

<Window x:Class="My.MainWindow"
    Title="Test" Height="350" Width="525">
        <local:LoggerControl x:Name="LogView" />

Even with something so simple, the Designer in Visual Studio 2010 can't load the main window. The error given is:

A value of type 'LoggerControl' cannot be added to a collectionor dictionary of type 'UIElementCollection'.

This error message has only one unrelated hit in the major search engines (plus duplicates) so I haven't found any useful help. Microsoft's own documentation seems to imply that this should work.

Any idea how to solve this?

share|improve this question
Strangely enough, when I build a minimal test application I do not have this issue. What could cause this? –  IanGilham Jun 28 '12 at 9:22
add comment

1 Answer

<UserControl x:Class="My.LoggerControl"


Looks like you may have made a mistake in the namespacing? LoggerControl is listed as being the namespace My, while you're importing My.LogTest and assigning it to the xml-prefix local. Change this to:


And I think it should work. Otherwise, fix the LoggerControl declaration.

share|improve this answer
Well spotted. That was a mistake in how I copied the code and removed the references to my employer, though. The namespaces I am using are correct. –  IanGilham Jun 28 '12 at 8:58
add comment

Your Answer


