我有一个适用于大型应用程序的NSIS脚本.我已经在网上阅读了很多线程,但无法得到以下明确答案:是否可以使用NSIS安装应用程序,当启动时(无论用户类型如何)自动以管理员身份运行?如果可能的话,如何实现?
注意:我已经强制要求NSIS包必须像admin使用一样运行
RequestExecutionLevel admin
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用此方法将UAC要求写入应用程序注册表项,但我无法获得RUNASADMIN编译命令,因为它不是NSIS所需的格式.
全部,我将一个日志文件写入.rtf文件,该文件具有格式下划线,粗体等.我保存了这个文件,并希望RichTextBox稍后再将其读回到持续格式化的文件中.我尝试了以下内容
tmpRichTextBox.LoadFile(@"F:\Path\File.rtf", RichTextBoxStreamType.RichText);
Run Code Online (Sandbox Code Playgroud)
它加载文件,但没有我的原始格式.如果我将.rtf加载到单词中,则会显示格式.我如何阅读.rtf RichTextBox 包括其格式?
谢谢你的时间.
我创建了以下CheckBox使用图像而不是a的自定义CheckBox.这很好用,但我希望能够根据需要更改图像.理想情况下,我想使用应用程序资源Properties.Resources.SomeImage16(.png文件).XAML是
<Style x:Key="styleCustomCheckBox"
TargetType="{x:Type CheckBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<StackPanel Orientation="Horizontal">
<Image x:Name="imageCheckBox"
Width="16"
Height="16"
Source="F:\Camus\ResourceStudio\Graphics\Images\UnPinned16.png"/>
<ContentPresenter VerticalAlignment="Center"/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="imageCheckBox"
Property="Source"
Value="F:\Camus\ResourceStudio\Graphics\Images\Pinned16.png"/>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="imageCheckBox"
Property="Source"
Value="F:\Camus\ResourceStudio\Graphics\Images\UnPinned16.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
随着实施
<ListBox SelectionMode="Single" >
<StackPanel Orientation="Horizontal">
<CheckBox Style="{StaticResource styleCustomCheckBox}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Margin="4,0,4,0"/>
<TextBlock VerticalAlignment="Top"
Text="SomeRecentDocument.resx"/>
</StackPanel>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
如何更改用于自定义的图像CheckBox(即更改固定/未固定到刻度/交叉等)而无需创建新样式/模板?
谢谢你的时间.
FileSystemWatcher当在UI线程的不同线程上引发监视文件更改时,我有一个和由此引发的事件.为了避免和交叉线程的声音乐趣,我试图使用
public void RaisePathChanged(object sender, RenamedEventArgs e)
{
Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
{
// Some code to handle the file state change here.
}));
}
Run Code Online (Sandbox Code Playgroud)
这个编译很好,并且RaisePathChanged它应该被解雇.但是,委托中的代码Action(() => { /*Here*/ })永远不会被调用/调用,代码只是被跳过.
为什么要跳过代码,我该如何修复它?这是确保代码在WPF中创建代码的最佳方式吗?
谢谢你的时间.
我有一个相当复杂的WPF应用程序(很像VS2013)IDocuments并且ITools停靠在应用程序的主shell中.Tools当主窗口关闭时,其中一个需要安全关闭,以避免进入"坏"状态.所以我使用Caliburn Micro的public override void CanClose(Action<bool> callback)方法来执行一些数据库更新等.我遇到的问题是这个方法中的所有更新代码都使用MongoDB Driver 2.0,这个东西是async.一些代码; 目前我正在尝试表演
public override void CanClose(Action<bool> callback)
{
if (BackTestCollection.Any(bt => bt.TestStatus == TestStatus.Running))
{
using (ManualResetEventSlim tareDownCompleted = new ManualResetEventSlim(false))
{
// Update running test.
Task.Run(async () =>
{
StatusMessage = "Stopping running backtest...";
await SaveBackTestEventsAsync(SelectedBackTest);
Log.Trace(String.Format(
"Shutdown requested: saved backtest \"{0}\" with events",
SelectedBackTest.Name));
this.source = new CancellationTokenSource();
this.token = this.source.Token;
var filter = Builders<BsonDocument>.Filter.Eq(
BackTestFields.ID, DocIdSerializer.Write(SelectedBackTest.Id));
var update = Builders<BsonDocument>.Update.Set(BackTestFields.STATUS, …Run Code Online (Sandbox Code Playgroud) 总而言之,对于上述主题存在许多疑问,但我认为这有足够的不同以保证一个新问题.我有以下Task和继续处理各种任务Status; TaskStatus.RanToCompletion,TaskStatus.Canceled和当然的AggregateException通过TaskStatus.Faulted.代码看起来像
Task<bool> asyncTask = Task.Factory.StartNew<bool>(() =>
asyncMethod(uiScheduler, token, someBoolean), token);
asyncTask.ContinueWith(task =>
{
// Check task status.
switch (task.Status)
{
// Handle any exceptions to prevent UnobservedTaskException.
case TaskStatus.RanToCompletion:
if (asyncTask.Result)
{
// Do stuff...
}
break;
case TaskStatus.Faulted:
if (task.Exception != null)
mainForm.progressRightLabelText = task.Exception.InnerException.Message;
else
mainForm.progressRightLabelText = "Operation failed!";
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都运作良好,但我担心我是否正确这样做,因为有可能AggregateException从延续中被抛出 - 那么呢?
我不想继续Wait我asyncTask的延续,因为这将阻止返回UI线程.捕捉从延续中抛出的任何异常并不意味着我必须做这样的事情
Task parentTask = …Run Code Online (Sandbox Code Playgroud) 所有,我精神崩溃了(这不是问题).我想转换List<string[]>为List<object[]>
List<string[]> parameters = GetParameters(tmpConn, name);
List<object[]> objParams = parameters.OfType<object[]>();
Run Code Online (Sandbox Code Playgroud)
这不起作用,但除非我忘记使用这种方法进行转换(不需要Lambda)?
谢谢你的时间.
所有,我已经开始使用MahApps.Metro了,但是这个库重写的一些控件(GroupBox例如)对我来说有点过于喧嚣.
我的问题是sinple:如果我想停止MahApps.Metro覆盖某个控件的风格,我该怎么办?
我试图DataGrid通过覆盖DataGrid创建我自己来解决此问题public class SomeDataGrid : DataGrid,这允许我将此控件用作WPF默认值.但是,为所有控件执行此操作是不理想的.
谢谢你的时间.
我必须跟随 ProgressIndicator
<MahAppsControls:ProgressIndicator Width="100"
Height="10"
VerticalAlignment="Center"
ProgressColour="White"
Visibility="{Binding ProgressVisibility}"/>
Run Code Online (Sandbox Code Playgroud)
并且在ViewModel中与此View实现相关联
private Visibility progressVisibility = Visibility.Collapsed;
public Visibility ProgressVisibility
{
get { return progressVisibility; }
set
{
if (value == progressVisibility)
return;
progressVisibility = value;
this.OnPropertyChanged("ProgressVisibility");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是这种绑定失败了,我不知道为什么.使用Snoop我有以下内容
System.Windows.Data错误:40:BindingExpression路径错误:在'object'''ProgressIndicator'(Name ='progressIndicator')'上找不到'ProgressVisibility'属性.BindingExpression:路径= ProgressVisibility; DataItem ='ProgressIndicator'(Name ='progressIndicator');
target元素是'ProgressIndicator'(Name ='progressIndicator'); 目标属性是'可见性'(类型'可见性')System.Windows.Data错误:40:BindingExpression路径错误:'对象'上没有'ProgressVisibility'属性'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' BindingExpression:路径= ProgressVisibility; DataItem ='ProgressIndicator'(Name ='progressIndicator');
target元素是'ProgressIndicator'(Name ='progressIndicator'); 目标属性是'可见性'(类型'可见性')System.Windows.Data错误:40:BindingExpression路径错误:'对象'上没有'ProgressVisibility'属性'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' BindingExpression:路径= ProgressVisibility; DataItem ='ProgressIndicator'(Name ='progressIndicator');
target元素是'ProgressIndicator'(Name ='progressIndicator'); 目标属性是"可见性"(类型"可见性")
我感谢有一个绑定错误,但我DataContext在App.xaml.cs中设置主窗口
MainWindow window = new MainWindow();
MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
// When the ViewModel …Run Code Online (Sandbox Code Playgroud) 我正在从头开始重写WinForms应用程序(它必须是WinForms,因为我想使用WPF和MVVM).这样做我选择使用MVC模式并尽可能使用依赖注入(DI)来提高可测试性,可维护性等.
我遇到的问题是使用MVC和DI.使用baisic MVC模式,控制器必须能够访问视图,并且视图必须能够访问控制器(有关WinForms示例,请参阅此处); 这导致使用Ctor-Injection时的循环引用,这是我的问题的关键.首先请考虑我的代码
Program.cs(WinForms应用程序的主要入口点):
static class Program
{
[STAThread]
static void Main()
{
FileLogHandler fileLogHandler = new FileLogHandler(Utils.GetLogFilePath());
Log.LogHandler = fileLogHandler;
Log.Trace("Program.Main(): Logging initialized");
CompositionRoot.Initialize(new DependencyModule());
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(CompositionRoot.Resolve<ApplicationShellView>());
}
}
Run Code Online (Sandbox Code Playgroud)
DependencyModule.cs
public class DependencyModule : NinjectModule
{
public override void Load()
{
Bind<IApplicationShellView>().To<ApplicationShellView>();
Bind<IDocumentController>().To<SpreadsheetController>();
Bind<ISpreadsheetView>().To<SpreadsheetView>();
}
}
Run Code Online (Sandbox Code Playgroud)
CompositionRoot.cs
public class CompositionRoot
{
private static IKernel ninjectKernel;
public static void Initialize(INinjectModule module)
{
ninjectKernel = new StandardKernel(module);
}
public static T Resolve<T>()
{
return …Run Code Online (Sandbox Code Playgroud) c# model-view-controller dependency-injection ninject winforms