小编A19*_*919的帖子

Wpf listview项目选择事件

我有两个ListView,每个列表包含一些行.我想在行选择后调用函数.但我有一个问题,当选择行或点击此行中的按钮时触发事件"GotFocus".当我使用<i:EventTrigger EventName="Selected">它时,当选择表中的行时不会触发.我需要做什么?

XAML:

<Grid>
    <ListView Width="200" Height="200" ItemsSource="{Binding Items}" HorizontalAlignment="Left">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Button Content="{Binding .}">
                </Button>
            </DataTemplate>
        </ListView.ItemTemplate>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="GotFocus">
                <i:InvokeCommandAction Command="{Binding DataContext.TestCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type vm:MainWindow }}}"></i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ListView>
    <ListBox Width="200" Height="200" ItemsSource="{Binding Items}" HorizontalAlignment="Right">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Button Content="{Binding .}">
                </Button>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="GotFocus">
                <i:InvokeCommandAction Command="{Binding DataContext.TestTestCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type vm:MainWindow }}}"></i:InvokeCommandAction>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </ListBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)

码:

namespace WpfApplication129
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview

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

城堡动态代理接口而不是派生类

namespace DynamicInterception
{
    public class Calculator
    {
        public virtual int Div(int a, int b)
        {
            try
            {
                return a / b;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                return 0;
            }
        }
    }

    [Serializable]
    public abstract class Interceptor : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            ExecuteBefore(invocation);
            invocation.Proceed();
            ExecuteAfter(invocation);
        }
        protected abstract void ExecuteAfter(IInvocation invocation);
        protected abstract void ExecuteBefore(IInvocation invocation);
    }

    public class CalculatorInterceptor : Interceptor
    {
        protected override void ExecuteBefore(Castle.DynamicProxy.IInvocation invocation)
        {
            Console.WriteLine("Start: {0}", invocation.Method.Name);
        }

        protected override void ExecuteAfter(Castle.DynamicProxy.IInvocation …
Run Code Online (Sandbox Code Playgroud)

c# proxy castle-windsor castle-dynamicproxy

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

JavaScript按几个月排序项目列表

我正在玩js脚本.如何按月对列表项进行排序.最好的方法是什么?

var dataCollection = [
        { values: { Month: { displayValue: "August" }, Sum: "10" } },
        { values: { Month: { displayValue: "February" }, Sum: "25" } },
        { values: { Month: { displayValue: "July" }, Sum: "35" } }
    ];
Run Code Online (Sandbox Code Playgroud)

我希望得到

dataCollection = [
            { values: { Month: { displayValue: "February" }, Sum: "25" } },
            { values: { Month: { displayValue: "July" }, Sum: "35" } },
            { values: { Month: { displayValue: "August" }, Sum: "10" …
Run Code Online (Sandbox Code Playgroud)

javascript

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

.Net Core 2.0 Visual Studio代码调试模式

当我在asp.net项目的调试中启动时,它会打开Edge

无法安全地连接到此页面,这可能是因为该站点使用了过时或不安全的TLS安全设置。如果这种情况持续发生,请尝试与网站所有者联系。尝试以下操作:返回最后一页

如何解决这个问题?

visual-studio-code asp.net-core

5
推荐指数
0
解决办法
570
查看次数

EF Core 存储过程不同的返回结果

我有这个存储过程

CREATE PROCEDURE [dbo].[GetBooksByAuthor2]
AS
    SELECT 
        books.Id, authors.Name AS Author, books.Name AS Book 
    FROM
        dbo.Authors authors
    INNER JOIN 
        dbo.AuthorsBooks authorsBooks ON authors.Id = authorsBooks.AuthorId
    INNER JOIN 
        dbo.Books books ON books.Id = authorsBooks.BookId
GO
Run Code Online (Sandbox Code Playgroud)

在 SQL Server Management Studio 中,结果如下所示:

Id| Author       | Book
--+--------------+----------
1 | FirstAuthor  | GoodBook1
2 | FirstAuthor  | GoodBook2
3 | FirstAuthor  | GoodBook3
1 | SecondAuthor | GoodBook1
3 | SecondAuthor | GoodBook3 
Run Code Online (Sandbox Code Playgroud)

在 EF Core 中,我为我的存储过程添加了一个视图模型

public class BookViewModel
{
    [Key]
    public int …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core

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

Mvvm模型ViewModel

它可以命名为MVVM模型吗?因为View通过ViewModelData与DataModel交互.View是否应仅与ViewModelData交互?我确实读过一些正确的MVVM模型应该在ViewModel中实现INotify但不在Model中.这样对吗?

namespace WpfApplication135
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ViewModelData();
    }
}
public class ViewModelData
{
    public DataModel DM { get; set; }
    public ViewModelData()
    {
        DM = new DataModel();
    }
}
public class DataModel : INotifyPropertyChanged
{
    public int label;
    public int Label
    {
        get
        {
            return label;
        }

        set
        {
            label = value;
            RaisePropertyChanged("Label");
        }
    }
    public DataModel()
    {
        Action …
Run Code Online (Sandbox Code Playgroud)

c# wpf mvvm

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

DeflateStream 复制到内存流

Tyring 压缩和解压缩,MemoryStream但似乎CopyTo不像预期的那样工作?为什么?如何解决这个问题?

public static MemoryStream Compress(MemoryStream originalStream)
{
    Console.WriteLine("Original before compressing size: {0}", originalStream.Length.ToString());
    MemoryStream compressedMemoryStream = new MemoryStream();

    using (DeflateStream deflateStream = new DeflateStream(compressedMemoryStream, CompressionMode.Compress, true))
    {
        originalStream.CopyTo(deflateStream);
    }
    Console.WriteLine("Compressed size: {0}", compressedMemoryStream.Length.ToString());
    return compressedMemoryStream;
}

public static void Decompress(MemoryStream compressedStream)
{
    Console.WriteLine("Compressed before decompressing size: {0}", compressedStream.Length.ToString());
    using (MemoryStream decompressedFileStream = new MemoryStream())
    {
         using (DeflateStream decompressionStream = new DeflateStream(compressedStream, CompressionMode.Decompress, true))
         {
              decompressionStream.CopyTo(decompressedFileStream);
         }
         Console.WriteLine("Decompressed size: {0}", decompressedFileStream.Length.ToString());
    }
}
Run Code Online (Sandbox Code Playgroud)

输出:

Original before …
Run Code Online (Sandbox Code Playgroud)

c# memorystream deflate

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

F#按元素求和两个序列

我正在寻找一种方法来按F#中的元素求和两个序列.

例如,如果我有这两个序列:

let first = seq [ 183.24; 170.15;174.17]
let second = seq [25.524;24.069;24.5]
Run Code Online (Sandbox Code Playgroud)

我想得到以下结果:

third list = [208.764;194.219;198.67]
Run Code Online (Sandbox Code Playgroud)

实现这一目标的最简单或最好的方法是什么?

f#

3
推荐指数
2
解决办法
214
查看次数

F# 在多维数组中写入值

我正在尝试计算协方差矩阵

运算符“expr.[idx]”已用于基于此程序点之前的信息的不确定类型的对象。考虑添加更多类型约束

CovMatrix.[a,b]

如何解决这个问题以及为什么会发生这种情况?

let FirstSeq = {1.0..10.0}
let SecondSeq = {20.0..30.0}

let All = seq {yield (0,FirstSeq); yield (1,SecondSeq)}

let cov(first:seq<float>)(second:seq<float>) =
    Seq.map2 (*) first second
    |> Seq.average
    |> fun x -> x - Seq.average first * Seq.average second

let CreateCovMatrix(strangeList:seq<int * seq<float>>) = 
    let Size = Seq.length strangeList
    let CovMatrix = Array2D.init Size Size
    let CalculateCovMatrix = 
        for (a, i) in strangeList do
            for (b, j) in strangeList do
                    CovMatrix.[a,b]=cov(i)(j)
    CalculateCovMatrix

let result = CreateCovMatrix(All)
printf "%A" result
Run Code Online (Sandbox Code Playgroud)

arrays f#

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

Func中的F#类型推断<double [],bool>

如何使用类型推断解决此问题?

open Microsoft.FSharp.Linq.RuntimeHelpers
open System
open System.Linq.Expressions
open Accord.Math.Optimization

module Vector=
    let compareScalarProcut(a:double[])(b:double[])(greaterOrEqualThen:float)=
         Array.map2 (*) a b 
        |> Array.sum
        |> fun x-> x >= greaterOrEqualThen

module Lambda =
    let toExpression (``f# lambda`` : Quotations.Expr<'a>) =
        ``f# lambda``
        |> LeafExpressionConverter.QuotationToExpression 
        |> unbox<Expression<'a>>


let LambdaExpression (coefficients:double[]) = 
    <@ Func<double[], bool>(fun i -> (Vector.compareScalarProcut(i,coefficients,0)) @> 
    |> Lambda.toExpression
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

f#

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