Reputation: 2454
I have kind-of a similar question to this post.
In a nutshell, if you create a dialog in WPF, you get from Visual Studio:
<Window x:Class="FrontEnd.View.Window1"
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:DiabetesFrontEnd.View"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">
...
created as part of the xaml, and
public partial class Window1 : Window
{
...
as the code behind. The questionner is asking about what happens to the xaml if you have a scenario with some base class scenario inserted, i.e.
public partial class Window1 : BaseWindow
{
.....
where
public class BaseWindow : Window
{
...
My question is an extension to this. What if you have the above scenario, but with
public class BaseWindow<T> : Window
{
...
and I'd obviously also have
public partial class Window1 : BaseWindow<SomeConcreteClass>
{
...
Is it possible to represent this hierarchy in xaml? If so, what does the xaml look like? I'm specifically thinking of using generics here, as opposed to objects. I've just hit a scenario where generics looks useful, but I'm not sure how to achieve it in WPF where xaml is involved. Many thanks.
Upvotes: 0
Views: 127
Reputation: 169370
Yes, you should use the x:TypeArguments directive in the XAML markup.
namespace WpfApp1
{
public class BaseWindow<T> : Window { }
public class SomeConcreteClass { }
}
Window1.xaml.cs:
public partial class Window1 : BaseWindow<SomeConcreteClass>
{
public Window1()
{
InitializeComponent();
}
}
Window1.xaml:
<local:BaseWindow x:Class="WpfApp1.Window1"
x:TypeArguments="local:SomeConcreteClass"
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:WpfApp1"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</local:BaseWindow>
Upvotes: 1