小编red*_*der的帖子

在InitializeComponent期间WPF获取控件空引用

所以我InitializeComponent在Window的构造函数中的方法调用正在运行XML并添加控件并将它们插入到它们的事件中.

因此,当其中一个控件的属性发生更改时,它会调用订阅该事件的Method.该方法引用尚未构建的控件.

为什么这会按此顺序发生?它在WinForms中有效,因为在创建所有控件之后,事件才会被激活.有没有办法在WPF中强制执行此操作?

我看到的其他解决方案是

  • 我需要在初始化后订阅事件.

  • 每当我处理一个控件时,我都需要检查null.

c# wpf

15
推荐指数
3
解决办法
8911
查看次数

向单个石英作业添加多个触发器

我想动态地向作业添加触发器,但无法从Scheduler中找到任何有用的方法

我虽然我只能重复调用scheduleJob方法,但这给了我ObjectAlreadyExists Exception"因为已经存在这个标识".

我怎样才能做到这一点?

编辑

private boolean scheduleLoadJob( XfuScheduleTimeInfo time )
{
    LoadScheduleJob job = new LoadScheduleJob( time );
    JobDetail detail;

    Integer id = Integer.valueOf( time.getScheduleId() );
    if( _hashMap.containsKey( id ) )
    {
        detail = _hashMap.get( Integer.valueOf( time.getScheduleId() ) );
    }
    else
    {
        detail = job.getDetail();
        _hashMap.put( id, detail );
    }

    try
    {
        Trigger newTrigger = job.getTrigger();
        _log.debug( "------" + newTrigger.getKey() );
        _quartzScheduler.scheduleJob( detail, newTrigger );
        return true;
    }
    catch( ParseException e )
    {
        _log.error( "Unable to parse cron expression …
Run Code Online (Sandbox Code Playgroud)

java dynamic repeat quartz-scheduler

13
推荐指数
2
解决办法
2万
查看次数

如何覆盖基类的==运算符,以便调用override

使用以下代码

public class Task
{
  string Name;
  public static bool operator ==(Task t1, Task t2)
  { return t1.Name = t2.Name && t1.GetType() == t2.GetType(); }
}
public class TaskA : Task
{
   int aThing;
   public static bool operator ==(TaskA t1, TaskA t2)
   { 
      return (Task)t1 == (Task)t2 && t1.GetType() == t2.GetType()
          && t1.aThing == t2.aThing; }
}
public class TaskB : Task  //more of the same

class Stuffin
{
   List<Task> Tasks;

   void CheckIt()
   {
      bool theSame = Tasks[0] == Tasks[1]; …
Run Code Online (Sandbox Code Playgroud)

c# operator-overloading equals-operator

6
推荐指数
3
解决办法
2848
查看次数

App xaml假设实例化的第一个窗口是主窗口(showdialog被忽略),我需要显示多个窗口

我在App.xaml.cs中有以下代码

private void App_Start(object sender, StartupEventArgs e)
{
  if ( CompletedInstall())
  {
    //using show to allow for pacifier if loading is slow
    var manager = new WINServiceConfig();
    MainWindow = manager;
    manager.ShowDialog();
  }
}

private bool CompletedInstall()
{
    var window = new Initialize();
    window.ShowDialog();
    return window.DoLaunchManager;
}
Run Code Online (Sandbox Code Playgroud)

以及App.xaml中的以下内容

<Application x:Class="Manager.App"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Startup="App_Start">
Run Code Online (Sandbox Code Playgroud)

当我注释掉检查线CompletedInstall()manager.ShowDialog()工作正常,和我的配置窗口显示.当CompletedInstall()被称为调用manager.ShowDialog()马上返回,而不显示窗口.我添加了主窗口,假设在某个地方有人决定应用程序应该只显示一个窗口.

我通过在调用CompletedInstall之前设置主窗口找到了一种解决方法

        private void App_Start(object sender, StartupEventArgs e)
        {
          var manager = new WINServiceConfig();
          MainWindow = manager;

          if (CompletedInstall())
          { …
Run Code Online (Sandbox Code Playgroud)

windows wpf app.xaml mainwindow

4
推荐指数
1
解决办法
1150
查看次数

受Quartz DisallowConcurrentExecution影响的工作会发生什么

由于禁止注释而导致作业未运行时会发生什么.

在当前运行的实例死后,它是否排队等待运行?它的重复"运行"是否被丢弃,永远不会被再次听到?

我已经尝试过在代码中测试,但是我对语言和库的经验不足导致了一些困难.

java concurrency quartz-scheduler

4
推荐指数
1
解决办法
1913
查看次数

使用<?有什么区别?在Java泛型中扩展SomeAbstract>与SomeAbstract

我正在从DotNet转向java,这种扩展的想法是新的.

我已经看到一些帖子完全解释了使用List<? extends SomeAbstract>vs. List<? super SomeAbstract>vs. List<SomeAbstract>,但我猜测在泛型中使用和不使用扩展之间没有区别.

真的吗?如果使用抽象类作为父级,答案会改变吗?

class My_AbstractExtends<T extends SomeAbstract>
Run Code Online (Sandbox Code Playgroud)

class My_Abstract<SomeAbstract>
Run Code Online (Sandbox Code Playgroud)

编辑

按如下方式创建子类

class My_ChildExtends extends My_AbstractExtends<ConcreteChildOfSomeAbstract>
Run Code Online (Sandbox Code Playgroud)

class My_Child extends My_Abstract<ConcreteChildOfSomeAbstract>
Run Code Online (Sandbox Code Playgroud)

java generics extends programming-languages abstract

4
推荐指数
1
解决办法
580
查看次数

visual studio 2010 intellisense将不会自动弹出一段时间

输入一段时间后,我无法让VS2010自动弹出.

我正在用C#编程,我尝试使用工具> TextEditor> C#> Intellisense下的设置,但没有运气.

我也尝试了100种不同的方式谷歌它没有运气.

settings intellisense visual-studio-2010

2
推荐指数
1
解决办法
1311
查看次数

C# 使用正则表达式分割 string.format 字符串

我希望能够在变量的位置指示器上拆分格式化字符串。它将删除花括号和它们之间指示数字的位置。
所以,字符串:

string format = "{0} field needs to be set to '{1}' when {2},  Fixit.  NOW!";
Run Code Online (Sandbox Code Playgroud)

应解析为 3 个字符串。

  • “该字段需要设置为‘”
  • “' 什么时候 ”
  • “,修复。现在!”

我们使用像上面的“格式”这样的字符串来构建错误消息。我的目标是添加通用单元测试,可以采用该格式并验证是否生成了与预期格式匹配的错误消息。由于错误生成代码和单元测试引用相同的格式,因此当对消息进行微小更改时,不需要更新单元测试。

在上面的示例中,我将能够通过调用名为 SplitFormatString 的新方法来测试预期结果。

string fieldName = "UserName";
string expectedValue = "Bob";
string condition = "excellence is a must";
string errorMessage = TestFieldValueErrorCase( );
AssertStringContainsAllThese(errorMessage, SplitFormatString(format), fieldName, expectedValue,condition);
Run Code Online (Sandbox Code Playgroud)

经过验证

public static void AssertStringContainsAllThese(string msg, string[] formatChunks, params string[] thingsToFind)
{
  foreach (var txt in formatChunks.Concat(thingsToFind))
  {
    Assert.IsTrue(msg.Contains(txt), "Could not find <<" + txt + ">> …
Run Code Online (Sandbox Code Playgroud)

c# regex string.format split

1
推荐指数
1
解决办法
2473
查看次数