Имя пользователя элементы управления без конструкторов по умолчанию в XAML

У меня есть пользовательский элемент управления без конструктора без параметров; назовем его WithoutDefaultConstructor . Я хочу вставить ] WithoutDefaultConstructor вызвал myControl в код XAML другого элемента управления (который называется MainWindow ). Однако я получаю эту ошибку компилятора:

Тип «WithoutDefaultConstructor» не может иметь атрибут Name. Ценность типы и типы без значения по умолчанию конструктор можно использовать как элементы в ResourceDictionary.

Как исправить это, не добавляя конструктор без параметров в WithoutDefaultConstructor ?

Вот содержимое MainWindow.xaml :

<Window x:Class="WpfApplication1.MainWindow"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" 
 Height="350" Width="525">
    <WpfApplication1:WithoutDefaultConstructor Name="myControl">
    </WpfApplication1:WithoutDefaultConstructor>
</Window>

Вот содержимое WithoutDefaultConstructor.xaml.cs :

using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class WithoutDefaultConstructor : UserControl
    {
        private int I_really_need_to_initialize_this_int;

        public WithoutDefaultConstructor(int i)
        {
            InitializeComponent();
            I_really_need_to_initialize_this_int = i;
        }
    }
}
6
задан user181813 27 May 2011 в 20:15
поделиться