无法在WPF中使用XamlWriter克隆UserControl

时间:2016-08-18 08:49:01

标签: c# wpf xaml user-controls

我需要克隆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);

0 个答案:

没有答案