小编zaz*_*aza的帖子

在wpf应用程序中捕获windows shutdown事件

我有一个ac#WPF应用程序,它需要在关闭时保存数据.如果用户关闭程序,则窗口关闭/关闭事件可正常工作,但如果用户注销/关闭计算机,则不会调用它们.

我已经找到了在winforms程序中捕获此事件的方法(此处此处).但我无法弄清楚如何在WPF应用程序中实现这一点.

我正试图停止关机,直到我的程序准备好退出

c# wpf wndproc

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

阻止窗口从任务管理器WPF中显示为"任务"c#

我有一个打开多个窗口的程序.我已经使用此方法将它们隐藏在ALT + TAB中.现在我需要新窗口停止显示在任务管理器的"任务"选项卡中.

我不需要在任务管理器中显示该过程,我只是不希望我的程序打开的所有窗口都显示在"任务"选项卡中.

这是我想要摆脱的图片:http://i1096.photobucket.com/albums/g324/thezaza101/Tasklist.jpg

-谢谢

c# wpf

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

将'System.Collections.Generic.IEnumerable <T>'转换为'System.Collections.ObjectModel.Collection <T>'

我有一个Collection,我正在尝试使用Distinct方法删除重复项.

public static Collection<MediaInfo> imagePlaylist

imagePlaylist = imagePlaylist.Distinct(new API.MediaInfoComparer());
Run Code Online (Sandbox Code Playgroud)

我得到错误"无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Collections.ObjectModel.Collection'.存在显式转换(您是否错过了转换?)"

imagePlaylist曾经是一个List(我可以使用.ToList()),但为了符合"CA1002不公开通用列表"我想将List转换为Collection.

-谢谢

c# linq generics collections implicit-conversion

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

子串,如果字符串不够长,则用空格替换字符

我正在尝试比较一个字符串的前3个字符,我正在尝试使用子字符串然后比较.

字符串是从输入文件中读取的,字符串可能不是3个字符长.如果一个字符串不是3个字符长,我希望substring方法用空格替换空字符.

我该怎么做呢?

当字符串不够长时,当前代码抛出一个exeption.

c# substring

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

VBA 类实例

我在 VBA 中遇到了一个问题,每次我向该数组添加内容时,数组中的每个项目都会被替换。

我试图遍历给定范围内的行并将其中的每一行转换为自定义类(在下面的示例中名为“CustomRow”)。还有一个管理器类(下面称为“CustomRow_Manager”),它包含一个行数组并具有添加新行的函数。

添加第一行后,它工作正常:https : //drive.google.com/file/d/0B6b_N7sDgjmvTmx4NDN3cmtYeGs/view?usp=sharing

但是,当它循环到第二行时,它会替换第一行的内容并添加第二个条目:https : //drive.google.com/file/d/0B6b_N7sDgjmvNXNLM3FCNUR0VHc/view?usp=sharing

关于如何解决这个问题的任何想法?

我创建了一些显示问题的代码,观察“CustomRow_Manager”类中的“rowArray”变量

宏文件 https://drive.google.com/file/d/0B6b_N7sDgjmvUXYwNG5YdkoySHc/view?usp=sharing

否则代码如下:

数据

    A   B   C
1   X1  X2  X3
2   xx11    xx12    xx13
3   xx21    xx22    xx23
4   xx31    xx32    xx33
Run Code Online (Sandbox Code Playgroud)

模块“模块 1”

Public Sub Start()
Dim cusRng As Range, row As Range
Set cusRng = Range("A1:C4")
Dim manager As New CustomRow_Manager
Dim index As Integer
index = 0
For Each row In cusRng.Rows
    Dim cusR As New CustomRow
    Call cusR.SetData(row, index)
    Call manager.AddRow(cusR) …
Run Code Online (Sandbox Code Playgroud)

excel vba class object

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

比较日期时出现 StackOverflowException

我的结构中有一个 DateTime 属性字段。我正在尝试验证输入日期以确保输入的值不是将来的值。

我正在使用以下代码:

public struct Car
{
    public DateTime Year
    {
        get
        {
            return Year;
        }

        set
        {
            if (value > DateTime.Now)
                throw new InvalidOperationException("Date cannot be in the futrure");
            else
                Year = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我现在尝试运行此代码时,我不断收到 StackOverflowException 并显示消息“无法计算表达式,因为当前线程处于堆栈溢出状态”。

关于为什么会这样或者如何解决这个问题有什么想法吗?

-谢谢。

c# stack-overflow datetime struct properties

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

JCL - 获取给定区域(大型机)中非空间字符的数量

我需要准备一些输入数据来运行程序,数据应该采用以下格式.

 UID (1-11)|TxtLen (12-16)| Text (17-62)
Run Code Online (Sandbox Code Playgroud)

我可以使用sort来正确定位字段并获取UID和文本字段.'TxtLen'应该包含从文本字段的开头到文本字段中的最后一个字符的字符数.

i.e. “Hello”’s TxtLen is 5, “Hel lo”’s TxtLen is 6, “Hello World”’s TxtLen is 11, etc...
Run Code Online (Sandbox Code Playgroud)

我想知道是否有办法通过JCL获取TxtLen,还是需要执行此操作的程序?

-谢谢

mainframe jcl

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

如何将表单输入绑定到字典值

我正在创建一个ASP.NET核心剃须刀页面Web应用程序,其中一个页面需要能够修改Dictionary<string, string>属性。

我尝试修改的对象如下:

public class Element
{
    [Key]
    public string ID {get;set;}
    public Dictionary<string, string> Values = new Dictionary<string, string>(); 
}
Run Code Online (Sandbox Code Playgroud)

我可以使用以下代码来支付页面上的值:

<form method="POST">
    <ul>
        <li hidden="true">ID: <input asp-for="FocusedItem.ID"/></li>
        @for (int i = 0; i < Model.FocusedItem.Values.Count(); i++)
        {
            <li>@Model.FocusedItem.Values.ElementAt(i).Key: <input asp-for="@Model.FocusedItem.Values.ElementAt(i).Value"/></li>
        }
    </ul>
    <br />
    <input type="submit" value="Submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

Pagemodel包含以下方法来处理发布事件:

public void OnPost(Element FocusedItem)
{
}
Run Code Online (Sandbox Code Playgroud)

“ ID”属性已正确填充,但是“ Values”属性的计数为0(表单上的输入值未绑定到词典)。如何解决这个问题?

另外还有一个问题-如何将新元素添加到字典中?

编辑:代码--cshtml:https: //raw.githubusercontent.com/thezaza101/RDMUI/master/Pages/Data/ElementManager.cshtml -cs:https : //raw.githubusercontent.com/thezaza101/RDMUI/master/Pages /Data/ElementManager.cshtml.cs

c# asp.net-core razor-pages

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

如果数组元素不存在则返回 null

如果数组元素不存在,是否有一种简单的方法来获取值“null”?

例如,下面的代码sArray有 3 个元素,前 3 个调用起作用SomeMethod(打印 true),但是第四个调用SomeMethod(sArray[3]);给了我一个IndexOutOfRangeException. 有没有办法让第四次调用SomeMethodprint 为 false?

    static void Main(string[] args)
    {
        int[] sArray = new int[]{1,2,3};
        SomeMethod(sArray[0]);
        SomeMethod(sArray[1]);
        SomeMethod(sArray[2]);
        SomeMethod(sArray[3]);
    }
    static void SomeMethod(int? s) => Console.WriteLine(s.HasValue);
Run Code Online (Sandbox Code Playgroud)

^更喜欢单行表达

c# arrays nullable .net-core

0
推荐指数
2
解决办法
3238
查看次数