小编Dan*_*986的帖子

For-each在JavaScript中的数组?

如何使用JavaScript循环遍历数组中的所有条目?

我以为它是这样的:

forEach(instance in theArray)
Run Code Online (Sandbox Code Playgroud)

theArray我的阵列在哪里,但这似乎是不正确的.

javascript arrays iteration foreach loops

4448
推荐指数
33
解决办法
392万
查看次数

WPF中的Datagrid - 1列默认排序

在WPF中,我有一个包含几列的DataGrid.

默认情况下,有1我想让它排序,但我不知道如何做到这一点.

XAML中的DataGrid如下所示:

<DataGrid x:Name="LibraryView" ItemsSource="{Binding Path=Elements[Persons]}" IsReadOnly="True" LoadingRow="dg_LoadingRow">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Name" Binding="{Binding Path=Element[Name].Value}" IsReadOnly="True" />
                <DataGridTextColumn Header="Score" Binding="{Binding Path=Element[Score].Value}" IsReadOnly="True" />
                <DataGridTextColumn Header="Date" Binding="{Binding Path=Element[Date].Value}" IsReadOnly="True" />
            </DataGrid.Columns>
        </DataGrid>
Run Code Online (Sandbox Code Playgroud)

它背后唯一的代码是:

public ScoreBoard()
{
    InitializeComponent();
    DataSet ds = dweMethods.DecryptAndDeserialize("ScoreData.xml");
    XElement TrackList = XElement.Parse(ds.GetXml());
    LibraryView.DataContext = TrackList;
}
Run Code Online (Sandbox Code Playgroud)

我找不到的是默认情况下如何按"分数"列进行排序.

任何人都可以帮我指出正确的方向吗?

c# sorting wpf datagrid

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

制作一组随机的int

我试图做的是生成随机int值的数组,其中随机值在min和max之间取得.

到目前为止,我想出了这段代码:

int Min = 0;
int Max = 20;

int[] test2 = new int[5];
Random randNum = new Random();
foreach (int value in test2)
{
    randNum.Next(Min, Max);
}
Run Code Online (Sandbox Code Playgroud)

但它还没有完全发挥作用.我想我可能只缺少1行或其他东西.任何人都可以帮我推动我朝着正确的方向前进吗?

c# arrays random int

27
推荐指数
1
解决办法
8万
查看次数

在WPF应用程序中按下Return键时如何模拟Tab键?

在WPF应用程序中,我有一个包含很多字段的窗口.当用户在填充每个字段后使用TAB键时,Windows会理解它会移动到下一个字段.这是非常了解的行为.

现在我想要的是,它使模拟TAB键,实际上RETURN被击中.所以在我的WPF xaml中,我添加了暗示KeyDown="userPressEnter"

在它背后的代码中:

private void userPressEnter(object sender, KeyEventArgs e)
{
  if (e.Key == Key.Return)
  {
    e.Key = Key.Tab // THIS IS NOT WORKING
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,显然这不起作用.但我不知道的是,我如何使这项工作?


编辑1 ==>找到一个解决方案

我找到了帮助我的东西=)

private void userPressEnter(object sender, KeyEventArgs e)
{
 if (e.Key == Key.Return)
 {
   TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
   MoveFocus(request);
 }
}
Run Code Online (Sandbox Code Playgroud)

这样,焦点移动到下一个它可以找到:)

c# wpf keypress

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

检测Ctrl + Enter

(使用WPF)我试图检测何时Ctrl+ Enter被击中.所以我尝试了这段代码:

if (e.Key == Key.Return && (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl))
 {
   //Do Something            
 }
Run Code Online (Sandbox Code Playgroud)

显然这是不正确的,因为它不起作用.任何人都可以帮助我,解释正确的方法应该是什么?

感谢名单

c# wpf keystroke

7
推荐指数
2
解决办法
7867
查看次数

逗号和(小数)点:他们需要不同的处理吗?

只是我想知道的事情.在欧洲,逗号我们主要用于小数(如20,001)但在欧洲以外的地方主要使用(如20.001)c#如何处理这个?如果应用程序将由欧洲和非欧洲人使用,编程时是否需要担心上述问题?

只是好奇这个.

c# point comma

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

检查文件是否正在使用中,等待文件完成

我在我的应用程序中遇到此问题:

  • 第1步 - 创建一个文件(xml)并在其中放入一些内容
  • 第2步 - 第三方应用程序将打开该文件并从步骤1中生成的文件中获取信息.
  • 第3步 - 再次删除文件.

我的第一个问题是这部分代码:

XmlDocument xmlDoc = new XmlDocument();
DataSet ds = //use a method to put in the data
xmlDoc.LoadXml(ds.GetXml());
xmlDoc.Save("Filename");
// ...
Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)

我的假设是否正确,只有在完成上述操作后才会执行最后一行?所以我可以100%确定数据是否都在xml中,然后才能尝试启动它?

我现在收到错误的第二部分是:

Process.Start(startInfo);
File.Delete("Filename");
Run Code Online (Sandbox Code Playgroud)

现在发生的事情是,在第三方程序将文件读​​入其内存之前,该文件已被删除.

有什么方法可以检查文件不再使用,或者做一些稳定的等待方式?

我已经找到了一种使用方法,Thread.Sleep(TimeInMiliSec);但我想这不是一种正确的方法(更像是一种解决方案)?

c# load file delete-file

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

How to make this code more efficient?

As i am not very advanced in C# yet, I try to learn how to make my code more efficient. I stored a lot of strings in some of the properties.

At the start of the application, i load all the seperatie properties into the textboxes. I now ise this code to load them all:

private void LoadStoredStrings()
{
    txtT1S1.Text = Properties.Settings.Default.strT1L1;
    txtT1S2.Text = Properties.Settings.Default.strT1L2;
    txtT1S3.Text = Properties.Settings.Default.strT1L3;
    txtT1S4.Text = Properties.Settings.Default.strT1L4;
    txtT1S5.Text = Properties.Settings.Default.strT1L5;
    txtT1S6.Text = Properties.Settings.Default.strT1L6;
    txtT1S7.Text = Properties.Settings.Default.strT1L7; …
Run Code Online (Sandbox Code Playgroud)

c# wpf properties

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

string.insert多个值.这可能吗?

我还在C#学习,有一件事我似乎无法找到答案.

如果我有一个看起来像这样的字符串"abcdefg012345",我想让它看起来像"ab-cde-fg-012345"

我想这样的事情:

  string S1 = "abcdefg012345";
            string S2 = S1.Insert(2, "-");
            string S3 = S2.Insert(6, "-");
            string S4 = S3.Insert.....
                ...
                ..
Run Code Online (Sandbox Code Playgroud)

现在我正在寻找是否有可能以某种方式将这个al变成1行,而不必制作所有这些字符串.

我认为这可能以某种方式?

c# string insert

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

将字符串拆分为包含在捕获括号中的数组

我的项目中有以下字符串:

((1,01/31/2015)(1,Filepath)(1,name)(1,code)(1,String)(1, ))

我想将此字符串分成几个部分,在这些部分中我可以获取捕获括号内的信息(例如1,Filepathor (1,Filepath),但整个字符串也位于捕获括号中,如您所见。然后我尝试将结果放入数组中string[] array = Regex.Split(originalString,SomeRegexHere)

现在我想知道最好的方法是什么,只需删除字符串的第一个和最后一个字符,这样我就没有捕获整个字符串的括号,或者是否有某种方法可以在此使用正则表达式来获取我想要的结果是?

c# regex string split

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