小编mca*_*lex的帖子

使用MVVM实现"关闭窗口"命令

所以我的第一次尝试完成了后面的代码,现在我正在尝试重构我的代码以使用MVVM模式,遵循MVVM 在框信息中的指导.

我已经创建了一个viewmodel类来匹配我的视图类,并且我将代码从代码中移出到viewmodel中,从命令开始.

我的第一个障碍是尝试实现一个"关闭"按钮,如果数据未被修改则关闭窗口.我已经装配了一个CloseCommand来替换'onClick'方法,除了代码试图运行的地方外,一切都很好this.Close().显然,由于代码已从窗口移动到普通类,因此'this'不是窗口,因此不可关闭.但是,根据MVVM,viewmodel不知道视图,所以我无法调用view.Close().

有人可以建议我如何从viewmodel命令关闭窗口?

c# wpf mvvm relaycommand

40
推荐指数
6
解决办法
5万
查看次数

Null To Boolean IValueConverter无法正常工作

如何使用IValueConverter将空值转换为布尔值?

我正在使用wpf来尝试显示一堆布尔值(在复选框中).创建新记录时,这些值为空,并在复选框中显示为"不确定".我希望空值出现并保存为"false"值.

我尝试创建一个NullToBoolean转换器,它从数据库中获取空值并将它们显示为false,然后在用户点击保存时将它们保存为false.(基本上,我试图避免用户必须在复选框中单击两次(一次使其成为真,然后再次使其成为假).这似乎适用于导入 - 即空值显示为false - 但除非我进行双击跳舞,当我保存时,数据库中的值不会改变.

我的转换器:

[ValueConversion(typeof(bool), typeof(bool))]
public class NullBooleanConverter : IValueConverter
{

  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
    if (value != null)
    {
      return value;
    }
    return false;
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
    if (value != null)
    {
      return value;
    }
    return null;
  }
}
Run Code Online (Sandbox Code Playgroud)

我试图让Converter工作的复选框之一:

    <CheckBox Grid.Column="1" Grid.Row="0" Padding="5" Margin="5" VerticalAlignment="Center" Name="chkVarianceDescriptionProvided" IsThreeState="False">
      <CheckBox.IsChecked>
        <Binding Path="VarianceDescriptionProvided" Mode="TwoWay">
          <Binding.Converter>
            <utils:NullBooleanConverter />
          </Binding.Converter> …
Run Code Online (Sandbox Code Playgroud)

c# wpf null ivalueconverter

8
推荐指数
2
解决办法
7964
查看次数

实体框架类型初始化程序异常

我有一个实体框架项目在我的机器上工作正常,但从网络运行时会出现问题.最近对该项目的更改包括添加Dynamic Linq dll(System.Linq.Dynamic)

当我从网络调试它时,VS报告: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

内部异常是:"无法加载文件或程序集'EntityFramework,Version = 4.4.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其依赖项之一.找到的程序集的清单定义与程序集引用不匹配.(例外情况HRESULT:0x80131040)":"EntityFramework,Version = 4.4.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089"}

我尝试了通常的技巧:packages从项目的根目录中删除目录,从包管理器控制台卸载并重新安装,但无济于事.

我的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="LGFinance.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <connectionStrings>
    <add name="LGFinanceEntities" connectionString="metadata=res://*/Model.LGFinanceContext.csdl|res://*/Model.LGFinanceContext.ssdl|res://*/Model.LGFinanceContext.msl;provider=System.Data.SqlClient; provider connection string='data source=lightning;initial …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework visual-studio-2012

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

Spring Batch-无法初始化读取器

解决方案:需要转换的.csv文件的文件路径错误。


我在尝试运行批处理spring应用程序时遇到一些问题。

目标:我想读取一个csv文件并将其加载到类上(我的老板告诉我),我确定知道的是我使用的代码示例直接将数据加载到MySQL。

在这里,我发布了我的项目的图片:

http://i.stack.imgur.com/ieEmK.png

-这里是文件-

App.java

package springbach;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
  public static void main(String[] args) {

    String[] springConfig  = 
        {   "database.xml", 
            "context.xml",
            "job-report.xml" 
        };

    ApplicationContext context = 
        new ClassPathXmlApplicationContext(springConfig);

    JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
    Job job = (Job) context.getBean("reportJob");

    try {

        JobExecution execution = jobLauncher.run(job, new JobParameters());
        System.out.println("Exit Status : " + execution.getStatus());

    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("Done");

  }
}
Run Code Online (Sandbox Code Playgroud)

Report.java …

java xml spring batch-processing

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

添加计算布尔列 SQL Server

如何将计算布尔 ( bit) 列添加到依赖于其他两个布尔列的 SQL Server 表中?(我更喜欢 SSMS 解决方案)。

我可以使用以下命令获得具有正确值的计算列:

case when ([ColumnA]=(1)) AND ([ColumnB]=(0)) then (1) else (0) end
Run Code Online (Sandbox Code Playgroud)

但当我在 C# 中使用数据时,结果列的类型int会失败

环顾四周,似乎我需要使用一个CAST语句,但我还没有弄清楚语法。我知道这行不通:

cast (case when ([ColumnA]=(1)) AND ([ColumnB]=(0)) then (1) else (0) end) as bit
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

c# sql-server-2008

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

用随机数填充我的数组?

我在测试类中将随机数放入数组时遇到了麻烦.代码在java中.我无法单独完成,因为最终我必须使用多达600个值来填充数组.这是测试类:

import java.util.Random;

public class test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        int size = 1000;
        int max = 5000; 
        int[] array = new int[size];
        int loop = 0; 

        Random generator = new Random();
        //Write a loop that generates 1000 integers and 
        //store them in the array using generator.nextInt(max)

        generator.nextInt(max); //generating one

        //I need to generate 1000
        //So I need some kind of loop that will generate 1000 numbers. 
        for (int i =0; i<1000; …
Run Code Online (Sandbox Code Playgroud)

java arrays random int

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

绑定到相关(详细)集合中第一项的属性

类似于WPF:如何仅绑定到集合中的一项,不使用 ItemsControl,因为我不想显示所有项,除非集合与主绑定项相关。所有数据都通过 EntityFramework 传入。与链接的问题一样,xaml 解释得最好:

<StackPanel Grid.Row="1" Orientation="Horizontal" DataContext="{Binding CurrentCustomer}">
  <StackPanel Orientation="Horizontal">
    <TextBlock Text="Total Orders:" />
    <TextBlock Text="{Binding Orders.Count}" />
  </StackPanel >

  <StackPanel Orientation="Horizontal">
    <TextBlock Text="First Order:" />
    <TextBlock Text="{Binding Orders.First.OrderDate}" />
  </StackPanel >
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我猜测由于我可以使用“Orders.Count”获取相关订单的计数,因此我尝试使用相同的 linq 语法来尝试检索 Orders.First (我也尝试过 Orders.FirstOrDefault),但是这是行不通的。

查看链接的问题,我尝试了Sheridan的 '[]' 语法,但 Orders[0].OrderDate 给出了输出错误: System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''HashSet'1' (HashCode=37425772)'. BindingExpression:Path=Orders[0].OrderDate; DataItem='Customer_<BigLongIdentityString>' (HashCode=21972018); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')。 …

c# wpf xaml

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

如何命令结构的向量

我正在为我的论文使用c ++和NS3.所以我想用stl函数排序对struct的向量进行排序,所以我将把我的头文件发布到我的向量所在的位置,我将解释我想做什么.

#include "ns3/net-device.h"
#include "ns3/object.h"
#include "ns3/log.h"
#include <vector>
#include <stdint.h>
#include "miscellaneous.h"


namespace ns3 {

/**
 * \brief The UeRecord class is developed in order to store at the eNodeB
 * all information (such as feedback cqi, mac address etc...) of a UE registered
 * into that eNodeB. All UE records are managed by the UeManager class
 */
class UeRecord : public Object
{
public:
  UeRecord ();
  ~UeRecord ();

  /**
   * \brief CqiFeedbacks represents a list of CQI …
Run Code Online (Sandbox Code Playgroud)

c++ overloading operator-keyword

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

EntityDataSource中的ContextCreating方法无法将实体转换为ObjectContext

使用EntityFramework,我在App_Code\DAL中创建了一个EntityDataModel(.edmx文件).在向导中,我将实体命名为"DLGDBEntities".我EntityDataSource在.aspx中有一些s,我将OnContextCreating属性设置为'UseSurveyContext',如下所示:

protected void UseSurveyContext(object sender, EntityDataSourceContextCreatingEventArgs e)
{
   e.Context = surveyContext;
}
Run Code Online (Sandbox Code Playgroud)

surveyContext的设置代码如下:

DLGDBEntities surveyContext;
Run Code Online (Sandbox Code Playgroud)

并在Page_Load中:

surveyContext = new DLGDBEntities();
Run Code Online (Sandbox Code Playgroud)

以上所有内容看起来与我在每个教程中看到的代码相同(例如:http://msdn.microsoft.com/en-us/library/cc668193.aspx#1),我可以发誓我已经拥有了它工作.

然而,现在,我收到错误: Cannot implicitly convert type 'DAL.DLGDBEntities' to 'System.Data.Objects.ObjectContext'

我做错了什么,为什么之前有效呢?

c# entity-framework objectcontext

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

Java递归迷宫求解器问题

我正在尝试使用递归编写一个迷宫求解器,它似乎尝试每个方向一次,然后停止,我无法弄清楚为什么.如果您发现问题,请告诉我.键0是开放空间1是墙2是路径3的一部分是迷宫的末端

public class Maze{
  public static void main(String[] args){
    int[][] maze = 
     {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
      {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,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0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1},
      {1,0,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1,0,1,0,1},
      {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1},
      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1}};
    boolean[][] posCheck = new boolean[maze.length][maze[0].length];
    int r = 0;
    int c = 0;
    for(int row = 0; row < maze.length; row++){
      for(int col = 0; col < maze[row].length; col++){
        if(maze[row][col]==0){
          r = row; …
Run Code Online (Sandbox Code Playgroud)

java recursion

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

按类型查找控件的祖先

UserControl在另一个中有一个“子项” UserControl(它充当 a 中的 TabItem TabControl)。在子项UserControl和 TabItem 祖先之间是许多其他控件(例如:Grids、 a StackPanel,可能是 aScrollViewer等)。

UserControl我想访问我的孩子中TabItem 的属性UserControl,并自定义一个通常 建议的递归函数,该函数沿着可视化树向上移动。但是,这总是在第一次空检查时返回true,直到我在逻辑树上添加查询。

代码:

public MyTabItem FindParentTabItem(DependencyObject child)
{
  DependencyObject parent = VisualTreeHelper.GetParent(child) ?? LogicalTreeHelper.GetParent(child);

  // are we at the top of the tree
  if (parent == null)
  {
      return null;
  }
  MyTabItem parentTabItem = parent as MyTabItem;
  if (parentTabItem != null)
  {
    return parentTabItem;
  }
  else
  {
    //use recursion until …
Run Code Online (Sandbox Code Playgroud)

c# wpf visualtreehelper

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