小编Sza*_*zsi的帖子

ListView ManipulationCompleted事件在手机上不起作用

我在Windows 10 UWP应用程序中有此代码:

MyListView.ManipulationMode = ManipulationModes.TranslateX;
MyListView.ManipulationStarted += (s, e) => x1 = (int)e.Position.X;
MyListView.ManipulationCompleted += (s, e) =>
{
    x2 = (int)e.Position.X;
    if (x1 > x2)
    {
        DataController.PaneOpen(false);
    };
    if (x1 < x2)
    {
        DataController.PaneOpen(true);
    };
};
Run Code Online (Sandbox Code Playgroud)

ManipulationCompleted活动无法在手机上播放ListView.处理程序内的代码永远不会被调用.它在PC上工作正常,但在手机上不起作用.我不明白为什么.

c# windows-10 windows-10-mobile uwp windows-10-universal

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

使用javascript函数的三种不同方式,但我不知道它的优缺点.有人可以解释这些差异吗?

我有三种方法来制作一个函数并返回它.(也许还有更多?)但我不知道它们之间的差异以及何时使用它们.请有人解释一下.

var test1 = function() {
    var funk1 = function() {
        console.log(1);
    }
    var funk2 = function(msg) {
        console.log(msg);
    }
    return {
        funk1: funk1,
        funk2: funk2
    }
};

var test2 = function() {
    this.funk1 = function() {
        console.log(1);
    }
    this.funk2 = function(msg) {
        console.log(msg);
    }
};

var someThing = test1();
someThing.funk1();
someThing.funk2(2);

var someThing = new test1();
someThing.funk1();
someThing.funk2(2);

var thingElse = new test2();
thingElse.funk1();
thingElse.funk2(2);
Run Code Online (Sandbox Code Playgroud)

javascript

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

检查两个字符串数组中是否有相同的元素?

我有两个包含值的字符串数组.如何检查第一个数组是否包含同样位于第二个数组中的元素?我想创建一个循环来检查两者中是否有任何相同的元素,然后我想使用该值并将其显示在消息框中.我该怎么比较呢?

string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
string[] potenDays = { "Mon", "Tue", "None", "None", "None", "None", "None" };
Run Code Online (Sandbox Code Playgroud)

c# arrays

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

如何按名称扫描和终止进程

我想创建一个程序,它将按名称扫描并终止进程.我找到了这个:

foreach (Process process in Process.GetProcessesByName("vlc"))
{
    process.Kill();
    process.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)

问题是,这只会杀死一次并关闭.我想要的是程序如果再次启动则继续并再次终止该进程.有任何想法吗?

c#

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

Moq 设置 ServiceLocator

我正在尝试为单元测试设置服务定位器,如下所示:

var mockS = new Mock<IServiceLocator>();
ServiceLocator.SetLocatorProvider(() => mockS.Object);
mockS.Setup(x => x.GetInstance<IObjectFactoryMethod<IAddress>>()).Returns(new Mock<ObjectsFactory>().Object);

var factoryMock = new Mock<IObjectFactoryMethod<IAddress>>(MockBehavior.Strict);
factoryMock.Setup(x => x.Create(null)).Returns(new Mock<IAddress>());

var factory = ServiceLocator.Current.GetInstance<IObjectFactoryMethod<IAddress>>();

// testing - factory returns null
var address = factory.Create(null); // address is null
Run Code Online (Sandbox Code Playgroud)

代码执行良好。工厂在调试期间显示为模拟工厂,但是当调用 Create(null) 时,它返回 null 而不是新的 IAddress 模拟。

.net c# moq

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

静态覆盖/抽象方法 - 任何好的解决方法?

我有一个抽象的基本配置类和两个实现:

public abstract class BaseConfiguration
{
}

public class LoginConfiguration : BaseConfiguration
{
    public LoginConfiguration() 
    {
    }

    public string Name { get; set; }
    public string Password { get; set; }
}

public class TestConfiguration : BaseConfiguration
{
    public TestConfiguration()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我面临的问题:每个特定的类类型都有一个明确的文件名.这意味着LoginConfiguration有一个名为"login.xml"的文件名,TestConfiguration指向"test.xml".

我希望稍后用于反序列化的文件名:

static void Main(string[] args)
{
    LoginConfiguration login = ReadFromFile<LoginConfiguration>();
    Console.ReadLine();
}

private static TConfig ReadFromFile<TConfig>() where TConfig : BaseConfiguration
{
    //Something like this needs to be done here:
    string filename = TConfig.GetFilename();

    //Deserialize file and …
Run Code Online (Sandbox Code Playgroud)

c#

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

使用 C# 根据计数和单词拆分字符串

我需要按单词拆分字符串,每行应有 25 个字符。例如:

string ORIGINAL_TEXT = "请编写一个程序,将此文本分成小块。每个块的最大长度应为 25 "

输出应该是:

“请写一个程序”,

“这破坏了这个文本”,

“分成小块。每个”,

“块应该有一个”,

“最大长度为25”

我尝试使用子字符串- 但它破坏了像

请写一个程序” - 错误

请写一个程序” - 正确

请写一个程序 - 只有 23 个字符,它可以需要更多 2 个字符,但它会破坏这个单词

string[] splitSampArr = splitSamp.Split(',', '.', ';');
string[] myText = new string[splitSampArr.Length + 1];

int i = 0;
foreach (string splitSampArrVal in splitSampArr)
{
    if (splitSampArrVal.Length > 25)
    {
        myText[i] = splitSampArrVal.Substring(0, 25);
        i++;
    }
    myText[i] = splitSampArrVal;

    i++;
}
Run Code Online (Sandbox Code Playgroud)

c# regex string split substring

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

基于条件的WPF Binding.ValidationRules

我现在有TextBox一个Binding.ValidationRules的工作等;

<TextBox>
    <Binding Path="MyID" NotifyOnValidationError="True" ValidatesOnDataErrors="True" 
             Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnSourceUpdated="True" 
             NotifyOnTargetUpdated="True" Delay="100">
        <Binding.ValidationRules>
            <local:IDValidator ValidatesOnTargetUpdated="True" table="Items"  />
        </Binding.ValidationRules>
    </Binding>
</TextBox>
Run Code Online (Sandbox Code Playgroud)

和风俗ValidationRule

public class IDValidator : ValidationRule
{
    public string table { get; set; }

    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        //Logic
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是在某些条件下我想IDValidator成为ValidationRule。其他时候我可能想说IDValidator2ValidationRule

现在,我找不到实现此目的的方法。所以我想起了为什么不将另一个值向下发送IDValidator,然后按照Validate

XMAL更新:

<local:IDValidator ValidatesOnTargetUpdated="True" table="Items" testing="{Binding Path=test}"  />
Run Code Online (Sandbox Code Playgroud)

IDValidator更新:

public string testing { get; set; }
Run Code Online (Sandbox Code Playgroud)

问题是似乎不喜欢向下发送绑定值。我该怎么做?

c# wpf

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

Angular + Dragula - 确认放置事件

当我将一个元素放入一个新包中时(我使用的是角1.4.8和angular-dragula),我想显示一个确认模态对话框(UI工具包).如果我单击确定,我想继续该过程,但如果我单击否,我希望该元素回到他的原始包.

到目前为止这是我的代码:

dragulaService.options($scope, 'tasks', {
    revertOnSpill: true
});

$scope.$on('tasks.drop', function (e, el, target, source) {
    if (target[0].id == 'done') {
        UIkit.modal.confirm("Are you sure?", function(){
            console.log('drag confirmed');
        }, function(){
            // the function cancelling the drop...
        });
    } else {
        console.log('drag confirmed - no modal required');
    }
});
Run Code Online (Sandbox Code Playgroud)

到目前为止,我的对话框显示完美,如果我单击否,事件被触发,我只是无法找到如何取消掉落(我试图找到dragula的文档,但无法使它工作.

谢谢.

javascript angularjs dragula

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