后台代码
private void UpdateSelectedView(SampleTreeViewItem treeViewItem)
{
if (treeViewItem != null)
{
Type type = treeViewItem.SampleType;
if (type != null)
{
string name = type.FullName;
Assembly assembly = GetType().Assembly;
Type sampleType = assembly.GetType(name);
var page = (FrameworkElement)Activator.CreateInstance(sampleType);
SampleContentControl.Content = page;
if (page is HomePage homePage)
{
homePage.NavigateTo += OnNavigateTo;
}
}
}
}
XML
<Grid Grid.Column="1">
<ContentControl HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Name="SampleContentControl" />
</Grid>