I try to make Visual C# app, which is using UserControl (WPF). By default, VS Community 2015 C# generates UserControl in the same namespace as main program. It's built correctly. I'd like to separate it in it's own namespace for possible future reuse. I change auto-generated code to have UserControl in separate namespace.
Here is my code
UserControl
<UserControl x:Class="nsTabI2CMemRW.TabI2CMemRW"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:nsTabI2CMemRW"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="500">
<Grid>
<TextBox x:Name="AddrH"/>
<Label x:Name="AddrH_Label"/>
</Grid>
C# class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication1; // This is my main app namespace
namespace nsTabI2CMemRW
{
/// <summary>
/// Interaction logic for TabI2CMemRW.xaml
/// </summary>
public partial class TabI2CMemRW : UserControl
{
public TabI2CMemRW()
{
//InitializeComponent();
((WpfApplication1.MainWindow)Application.Current.MainWindow).InitializeComponent(); //InitializeComponent();
}
}
}
Main Windows 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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:UserControl="clr-namespace:nsTabI2CMemRW"
mc:Ignorable="d"
Title="MainWindow" Height="649.005" Width="620.667" ScrollViewer.CanContentScroll="True">
<Grid>
<TabControl x:Name="tabControl" Margin="0,0,0.4,0.2">
<TabControl.BindingGroup>
<BindingGroup/>
</TabControl.BindingGroup>
<TabItem x:Name="I2CMemReadWrite" Header="I2C Mem Read/Write">
<UserControl:TabI2CMemRW Margin="0,0,-0.2,278.2"/>
</TabItem>
<TabItem Header="TabItem">
<Button x:Name="button" Content="Button" Height="100" Width="75"/>
</TabItem>
</TabControl>
</Grid>
Designer shows error "Object reference is not set to an instance of an object" for line
<UserControl:TabI2CMemRW Margin="0,0,-0.2,278.2"/>
Program compiled fine but first tab (where my UserControl should be) is blank.