I have a set of UserControl
s in a library, but because the library is in a different namespace than the MainWindow
, I don't seem to be able to get one UserControl
to retrieve List<features>
from MainWindow
.
I suspect this is because UserControl
does not know of MainWindow
, and it's not meant to, as it is in a DLL library. As the UserControl
is in a DLL, it should be agnostic to namespaces, but still be able to get what it needs.
So below I put some XAML and relative C# code-behind where you can see on the UserControl
s ListBox
, I'm trying to retrieve the features
list from MainWindow
.
<UserControl x:Class="FlatControls.MyListBox"
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:FlatControls"
mc:Ignorable="d"
d:DesignHeight="34" d:DesignWidth="100" MaxHeight="34" MaxWidth="100" x:Name="root">
<ListBox x:Name="listBox">
</UserControl>
public MyListBox()
{
InitializeComponent();
listBox.Items = ???????????
}
<Window x:Class="MyApp.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:WpfApp4"
xmlns:FC="clr-namespace:FlatControls;assembly=FlatControls"
mc:Ignorable="d"
Title="MainWindow" Height="1000" Width="1900" WindowState="Maximized" RenderOptions.BitmapScalingMode="Fant">
<Grid>
xyz
</Grid>
<Window>
namespace MyApp
{
public List<string> features = new List<string>();
public MainWindow()
{
InitializeComponent();
features.Add("Concave");
features.Add("Convex");
}
}
Any help would be greatly appreciated, whether it's via Binding, or code-behind :D