好吧,我正在尝试同时使用 MahApps.Metro 和 Caliburn.Micro,但我遇到了一些问题
这是我的引导程序
public sealed class TestBootstrapper : Bootstrapper<ShellViewModel>
{
private CompositionContainer container;
protected override void Configure()
{
container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));
CompositionBatch batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new AppWindowManager());
batch.AddExportedValue<IEventAggregator>(new EventAggregator());
batch.AddExportedValue(container);
container.Compose(batch);
}
protected override object GetInstance(Type serviceType, string key)
{
string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
var exports = container.GetExportedValues<object>(contract);
if (exports.Count() > 0)
{
return exports.First();
}
return base.GetInstance(serviceType, key);
}
}
这是我的 AppWindowManager
public sealed class AppWindowManager : WindowManager
{
static readonly ResourceDictionary[] resources;
static AppWindowManager()
{
resources = new ResourceDictionary[]
{
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml", UriKind.RelativeOrAbsolute) },
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml", UriKind.RelativeOrAbsolute) },
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml", UriKind.RelativeOrAbsolute) },
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml", UriKind.RelativeOrAbsolute) },
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml", UriKind.RelativeOrAbsolute) },
new ResourceDictionary
{ Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml", UriKind.RelativeOrAbsolute) }
};
}
protected override Window EnsureWindow(object model, object view, bool isDialog)
{
MetroWindow window = view as MetroWindow;
if (window == null)
{
window = new MetroWindow()
{
Content = view,
SizeToContent = SizeToContent.WidthAndHeight
};
window.MinHeight = 150;
window.MinWidth = 500;
foreach (ResourceDictionary resourceDictionary in resources)
{
window.Resources.MergedDictionaries.Add(resourceDictionary);
}
window.SetValue(View.IsGeneratedProperty, true);
Window owner = this.InferOwnerOf(window);
if (owner != null)
{
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.Owner = owner;
}
else
{
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}
else
{
Window owner2 = this.InferOwnerOf(window);
if (owner2 != null && isDialog)
{
window.Owner = owner2;
}
}
return window;
}
}
这有点工作,但我的窗口周围有一个黑色边框,直到我调整大小,见下图
为什么有黑色边框,我怎样才能摆脱它(如果我手动调整窗口大小,边框就会消失。)?