在具有从基类继承的多个窗口的应用程序中 BaseWindow ,我想在每个窗口上都有一个状态栏 . 我假设这必须用代码完成,因为一个XAML生成的类不能从另一个继承 .
XAML看起来像这样:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication1">
和BaseWindow类:
public class BaseWindow : Window {
protected override void OnContentChanged(object oldContent, object newContent) {
var sb = new StatusBar();
sb.Items.Add(new TextBlock {
Text = "Status bar"
});
var dp = new DockPanel();
dp.Children.Add(sb);
DockPanel.SetDock(sb, Dock.Bottom);
dp.Children.Add((UIElement)newContent);
base.OnContentChanged(oldContent, dp);
}
}
引发以下错误: Must disconnect specified child from current parent Visual before attaching to new parent Visual.
我该如何解决这个问题?或者,我可以用什么其他技术来实现这一目标?