小编CDs*_*ace的帖子

可重复使用的代码,可在双击时使矩形不透明度为零

我有一些矩形,当你双击它们所在的屏幕时,我想让它"出现":

<StackPanel>
    <Rectangle Name="MyRect1" Opacity="0" Height="100" DoubleTapped="MyRect1_DoubleTapped" Fill="Aqua" />
    <Rectangle Name="MyRect2" Opacity="0" Height="100" DoubleTapped="MyRect2_DoubleTapped" Fill="Black"/>
    <Rectangle Name="MyRect3" Opacity="0" Height="100" DoubleTapped="MyRect3_DoubleTapped" Fill="Blue"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

我目前的代码背后 - 这有效:

private void MyRect1_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    MyRect1.Opacity = 1;
}

private void MyRect2_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    MyRect2.Opacity = 1;
}

private void MyRect3_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
    MyRect3.Opacity = 1;
}
Run Code Online (Sandbox Code Playgroud)

由于我可能需要十几个或更多这些出现的矩形,有没有办法只为所有这些使用一个事件处理程序?

即,而不是为每个矩形都有一个处理程序,有类似的东西:

<StackPanel>
    <Rectangle Name="MyRect1" Opacity="0" Height="100" DoubleTapped="MyRect_DoubleTapped" Fill="Aqua" />
    <Rectangle Name="MyRect2" Opacity="0" Height="100" DoubleTapped="MyRect_DoubleTapped" Fill="Black"/>
    <Rectangle Name="MyRect3" Opacity="0" Height="100" DoubleTapped="MyRect_DoubleTapped" Fill="Blue"/> …
Run Code Online (Sandbox Code Playgroud)

c# xaml uwp

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

strip命令不会删除字符串中的"e"

我试图从给定的单词中删除元音并返回单词.

例如

word = "helleeEoo"
Run Code Online (Sandbox Code Playgroud)

如果我使用如下所示的strip命令,我输出的是"hell"而不是"hll"

word = word.strip("aAeEiIoOuU")
Run Code Online (Sandbox Code Playgroud)

但如果我使用如下所示的join命令,它可以正常工作:

word = ''.join(c for c in word if c not in 'aAeEiIoOuU')
Run Code Online (Sandbox Code Playgroud)

我正在使用python 3,我想知道为什么在最终输出中出现strip命令'e'的情况?

python python-3.x

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

调用sess.run()时,Tensorflow会挂起

以下代码将挂起(只有一个CTRLz让我出局).

import tensorflow as tf
import cifar10 # from https://github.com/tensorflow/models/tree/master/tutorials/image/cifar10 (both cifar10.py & cifar10_input.py)

def main():
    print 'TensorFlow version: ',tf.__version__

    with tf.Session() as sess:

    with tf.device('/cpu:0'):
        images, labels = cifar10.distorted_inputs()

    input = tf.constant([[[1, 2, 3], [5, 5, 5]], [[4, 5, 6], [7, 7, 7]], [[7, 8, 9], [9, 9, 9]]])

    one=input[0]
    print "X1 ",type(input), one
    oneval = sess.run(one)
    print "X2 ",type(one), one, type(oneval), oneval

    two=images[0]
    print "Y1 ",type(images), two
    twoval = sess.run(two)
    print "Y2 ",type(two), two, type(twoval), …
Run Code Online (Sandbox Code Playgroud)

python session tensorflow

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

Python中的数学库和数组

我将使用数学库对数组进行一些计算.
我试过这样的事情:

import numpy as np
import math
a = np.array([0, 1, 2, 3])
a1 = np.vectorize(a)
print("sin(a) = \n", math.sin(a1)) 
Run Code Online (Sandbox Code Playgroud)

不幸的是它不起作用.发生错误:"TypeError: must be real number, not vectorize".

如何使用矢量化函数来计算那种东西?

python arrays math numpy vectorization

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

JavaScript监听器不断增加

我实现了一个Web应用程序,并使用谷歌开发人员工具监控性能.我注意到听众不断增加,堆也是如此.

在此输入图像描述

听众增加的部分看起来像这样

let ival = $interval(function () {
    $http.get('someurl') // this call is actually done through a service, don't know if that matters
}, 1000)
Run Code Online (Sandbox Code Playgroud)

我会理解,如果堆增长是因为一些数据没有被垃圾收集器收集,但我不明白为什么听众会增加?

这是一个可重复的,最小的例子:

index.html文件:

<!doctype html>
<html ng-app="exampleModule">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
    <script src="script.js"></script>
  </head>
  <body>
    <div ng-controller="someController">
    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

和script.js文件:

angular.module("exampleModule", [])
  .controller("someController", [ "$http", "$interval", function ($http, $interval) {

    $interval(function () {
      $http.get('script.js')
    }, 1000)

  }])
Run Code Online (Sandbox Code Playgroud)

观看演奏时的结果与上图中的相同.您应该使用简单的Web服务器来发出GET请求.

javascript google-chrome listeners angularjs

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

手动添加参数?

Aspnet.Core 上的 Swashbuckle 通常从方法签名中读取所需的参数,例如

[HttpGet]
[Route("/api/datasets/{id}")]
[SwaggerOperation("DatasetsIdGet")]
[SwaggerResponse(200, type: typeof(DataSet))]
public IActionResult DatasetsIdGet([FromRoute]string id)
{
    string exampleJson = null;

    var example = exampleJson != null ? JsonConvert.DeserializeObject<DataSet>(exampleJson) : default(DataSet);
    return new ObjectResult(example);
}
Run Code Online (Sandbox Code Playgroud)

ID 来自路由,可通过 Swagger-UI 和生成的规范获得。

不幸的是,我必须上传一些非常大的文件,并希望禁用某个方法的表单绑定

public async Task<IActionResult> Upload()
{
// drain fields manually. see https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads
// assume that there is the field bigupload.
}
Run Code Online (Sandbox Code Playgroud)

使用 Swagger-Editor 我可以很容易地描述这个场景 - 但是我如何说服 Swashbuckle 这个方法有 bigupload 作为必填字段?

编辑

这是我基于 swashbuckle github 中的一个线程的解决方案

public class ImportFileParamType : IOperationFilter
{

    /// <summary> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc swashbuckle

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

查询 - LINQ,2 个表,联合

这是我的两个表:

publicParking(publicParkingID, address, latitude, longtitude, status,
              PricePerHour, maxSpaces, occupiedSpaces, freeSpaces, isOrdered)
Run Code Online (Sandbox Code Playgroud)

parkingLot(parkingLotID, address, latitude, longtitude, status,
           PricePerHour, maxSpaces, occupiedSpaces, freeSpaces, isOrdered)
Run Code Online (Sandbox Code Playgroud)

除 ID 外,所有列都相同。

我需要在 LINQ 中编写查询,该查询将返回一个按价格排序的表,其中包含所有可用的停车位 ( publicParking/ parkingLot) - with status==true.

该表应如下所示:

ID地址纬度经度状态

我应该做一个联合,还是应该更改表格以便第一列只调用 ID?(而不是publicParkingIDparkingLotID

我试过这段代码,但它不起作用

var union =  
         (from lot in parkingLots
         where lot.status == true
         select lot).Union( from pub in publicParkings
         where pub.status==true
         select pub);
Run Code Online (Sandbox Code Playgroud)

它给出了这个错误:

错误

我正在使用 LINQPad5 和 tutorialsteacher 的代码编辑器。还有其他选择吗?

c# sql linq asp.net

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

根据其他列值进行条件替换

我有一个包含表的数据库:

********************************
* Code  *      FileName        *
********************************
* NULL  * Cats and Dogs        *
* C123  * C123 - Cats and Dogs *
* NULL  * Baking Cakes         *
* Z345  * Z345 - Plants        *
* F967  * E345 - Tractors      *
********************************
Run Code Online (Sandbox Code Playgroud)

我想返回所有行的文件名或操纵文件名,基于代码列中是否有值并且它与文件名中的代码匹配。

所以查询应该返回

Cats and Dogs
xxxx - Cats and Dogs
Baking Cakes
xxxx - Plants
E345 - Tractors
Run Code Online (Sandbox Code Playgroud)

从上面的一组数据来看。

我正在努力对另一列中的值进行条件替换 - 如果我使用 case 语句进行替换,我需要列出所有可能的代码,这将很难维护。有什么办法吗

Select Replace(FileName, Code, "xxxx") from table where filename like %Code%
Run Code Online (Sandbox Code Playgroud)

sql conditional replace

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

Create a temporary file with unique name using Python 3?

I would like to create a temporary file with an specific name (and if its possible with an specific extension).

Example:

-mytempfile.txt
-mytempfile2.xml
Run Code Online (Sandbox Code Playgroud)

I've been reading about tempfile library, but as far as I know I can only set the following parameters

(mode='w+b', buffering=None, encoding=None, newline=None, suffix=None, prefix=None, dir=None)
Run Code Online (Sandbox Code Playgroud)

python file temp python-3.x

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

DataAdapter.Update()不会更新DB中的数据

我有一个任务,要求我更新northwind数据库,我做了一些像教程所说的如下

我填写DataTable使用The DataAdapter.Fill(table).

Delete,Insert,Update使用构建命令CommangBuilder

SqlDataAdapter adapter = new SqlDataAdapter(selectStr, conn);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter); 
adapter.DeleteCommand = builder.GetDeleteCommand(true);
adapter.UpdateCommand = builder.GetUpdateCommand(true);
adapter.InsertCommand = builder.GetInsertCommand(true);
adapter.Fill(employees_table);
Run Code Online (Sandbox Code Playgroud)

我还为表设置了一个主键:

DataColumn[] employees_keys = new DataColumn[2];
employees_keys[0] = employees.Columns["EmployeeID"];
employees_table.PrimaryKey = employees_keys; 
Run Code Online (Sandbox Code Playgroud)

现在我试图删除并添加一行:

// accepts an employee object and creates a new new row with the appropriate values for 
// an employee table row 
DataRow row = ConvertEmployeeToRow(employeeToAdd);
employee_table.Rows.Add(row);`
Run Code Online (Sandbox Code Playgroud)

并删除一行:

DataRow row = employees.Rows.Find(employeeToDismiss.ID);
employees.Rows.Remove(row); 
Run Code Online (Sandbox Code Playgroud)

我还应该指出,我试图使用row.SetAdded()row.Delete() …

c# ado.net

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