में डिफ़ॉल्ट कन्स्ट्रक्टर के बिना उपयोगकर्ता नियंत्रण नामकरण मेरे पास पैरामीटर रहित कन्स्ट्रक्टर के बिना उपयोगकर्ता नियंत्रण है; आइए इसे WithoutDefaultConstructor
पर कॉल करें। मैं WithoutDefaultConstructor
को myControl
नामक एक अन्य नियंत्रण के XAML कोड में डालना चाहता हूं (जिसे MainWindow
कहा जाता है)। WithoutDefaultConstructor
करने के लिए एक parameterless निर्माता जोड़े बिनाXAML
The type 'WithoutDefaultConstructor' cannot have a Name attribute. Value types and types without a default constructor can be used as items within a ResourceDictionary.
मैं इसे ठीक कैसे करूँ: हालांकि, मैं इस संकलक त्रुटि मिलती है?
यहाँ 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;
}
}
}