我想我错过了一些明显的东西。但由于我的应用程序的主窗口是由
启动的UserControlprotected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<MainWindowViewModel>();
}
在我的引导程序中如何设置窗口本身的图标和工具栏中的应用程序?
答案 0 :(得分:7)
基于XAML的解决方案:将您的MainWindowView
基类从UserControl
更改为Window
(在.xaml和.xaml.cs中) ,然后在xaml中设置您的Icon
属性或任何其他特定于窗口的属性。
基于代码的解决方案:DisplayRootViewFor<T>
采用可选的设置参数:
var settings = new Dictionary<string, object>
{
{ "Icon", new BitmapImage(new Uri("pack://application:,,,/WpfApplication2;component/icon.png")) },
{ "ResizeMode", ResizeMode.NoResize }
};
DisplayRootViewFor<IShell>(settings);
键应对应于您要设置的窗口属性,并且值类型必须匹配。
答案 1 :(得分:1)
// windowmanager.createwindow的默认设置
public interface IPropertyKeyValue
{
string Key { get; }
object Value { get; }
}
public class PropertyKeyValue : IPropertyKeyValue
{
public string Key { get; set; }
public object Value
{
get;
set;
}
}
public class PropertyKeyValue<TValue> : IPropertyKeyValue
{
object IPropertyKeyValue.Value { get { return this.Value; } }
public string Key { get; set; }
public TValue Value { get; set; }
}
public class IconProperty : PropertyKeyValue<ImageSource>
{
}
public class WindowManager : Caliburn.Micro.WindowManager
{
public List<IPropertyKeyValue> DefaultSettings { get { return _defaultSettings; } }
private readonly List<IPropertyKeyValue> _defaultSettings = new List<IPropertyKeyValue>();
private void Populate(ref IDictionary<string, object> settings)
{
if (DefaultSettings != null && DefaultSettings.Count > 0)
{
if (settings == null)
settings = new Dictionary<String, object>();
foreach (var prop in DefaultSettings)
{
settings[prop.Key] = prop.Value;
}
}
}
protected override System.Windows.Window CreateWindow(object rootModel, bool isDialog, object context, IDictionary<string, object> settings)
{
Populate(ref settings);
return base.CreateWindow(rootModel, isDialog, context, settings);
}
}
//bootstrapper
protected override object GetInstance(Type service, string key)
{
if (service == typeof(IWindowManager))
return this.Application.FindResource("wm");
return base.GetInstance(service, key);
}
/*
<local:WindowManager x:Key="wm">
<local:WindowManager.DefaultSettings>
<local:IconProperty Key="Icon" Value="favicon.ico"/>
</local:WindowManager.DefaultSettings>
</local:WindowManager>
*/
答案 2 :(得分:1)
这里有一个我做事的例子。我只是将其放在窗口定义中。
let userName = req.body.userName
//wait till query result
let docs = await connection.connectedusers.updateMany({}, { $push: { connectArray: [userName] } }, { upsert: true });
//wait till query result
let list = await connection.connectedusers.find({});
//this will wait for 10 secs
await new Promise((resolve, reject) => {
setTimeout(async () => {
resolve(1);
}, 10000);
});
//then process result
if (list[0].connectArray.length >= 2) {
let shortListed = list[0].connectArray.slice(0, 2);
console.log(shortListed,'shortlisted array')
try {
await connection.connectedusers.update({},
{ $pull: { connectArray: { $in: shortListed } } },
{ multi: true }
);
const docs = await connection.connectedusers.find({});
res.json({
message: 'users selected successfully',
status: 1,
docs: docs
});
} catch (err) {
res.status(201).json(err);
}
} else {
const docs = await connection.connectedusers.find({});
console.log(docs, 'docs')
const allUsers = docs.connectArray;
console.log(allUsers, 'allUsers')
await connection.connectedusers.update({},
{ $pull: { connectArray: { $in: allUsers } } },
{ multi: true }
)
res.json({
message: 'users not selected',
status: 2,
docs: docs,
allUsers: allUsers
})
}