我需要克隆UserControl(TabItem Content)以将其包含到Canvas中。我尝试过使用XamlWriter,它会抛出NullReference Exception ..
string gridXaml = XamlWriter.Save(Plot.Plot_MV.plotWindow.bremsPlot.Content);
这里是我的.xaml
<TabControl x:Name="plot_TabControl" Margin="0"
Grid.RowSpan="2" Grid.Row="1"
Grid.Column="0" Grid.ColumnSpan="3"
Style="{DynamicResource ResourceKey=TabControl_Style}" SelectionChanged="plot_TabControl_SelectionChanged"
>
<TabItem Header="Bremskraft" Style="{DynamicResource ResourceKey=TabItem_Style}"
x:Name="bremsPlot" Margin="0,0,0,40">
</TabItem>
在后面的代码中我通过创建一个新的UserControl类来包含内容
bremsPlot.Content = new Bremskraft.Bremskraft_Plot(calcClass);