我在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上工作正常,但在手机上不起作用.我不明白为什么.
我有三种方法来制作一个函数并返回它.(也许还有更多?)但我不知道它们之间的差异以及何时使用它们.请有人解释一下.
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) 我有两个包含值的字符串数组.如何检查第一个数组是否包含同样位于第二个数组中的元素?我想创建一个循环来检查两者中是否有任何相同的元素,然后我想使用该值并将其显示在消息框中.我该怎么比较呢?
string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
string[] potenDays = { "Mon", "Tue", "None", "None", "None", "None", "None" };
Run Code Online (Sandbox Code Playgroud) 我想创建一个程序,它将按名称扫描并终止进程.我找到了这个:
foreach (Process process in Process.GetProcessesByName("vlc"))
{
process.Kill();
process.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)
问题是,这只会杀死一次并关闭.我想要的是程序如果再次启动则继续并再次终止该进程.有任何想法吗?
我正在尝试为单元测试设置服务定位器,如下所示:
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 模拟。
我有一个抽象的基本配置类和两个实现:
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) 我需要按单词拆分字符串,每行应有 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) 我现在有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。其他时候我可能想说IDValidator2是ValidationRule。
现在,我找不到实现此目的的方法。所以我想起了为什么不将另一个值向下发送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)
问题是似乎不喜欢向下发送绑定值。我该怎么做?
当我将一个元素放入一个新包中时(我使用的是角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的文档,但无法使它工作.
谢谢.