在MainWindow中,命令绑定工作正常.在UserControl1中它不起作用.请注意,datacontext设置正确,因为按钮的内容是绑定的结果.
我不是试图将usercontrol中的命令绑定到mainwindow中的命令或任何其他此类欺骗.我只是想在UserControl1中复制我在MainWindow中所做的事情.
MainWindow XAML
<StackPanel>
<Button Content="Click Here" Command="{Binding ClickHereCommand}" Height="25" Width="90"></Button>
<local:UserControl1></local:UserControl1>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
MainWindow代码背后
public partial class MainWindow : Window
{
public static RoutedCommand ClickHereCommand { get; set; }
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
ClickHereCommand = new RoutedCommand();
CommandBindings.Add(new CommandBinding(ClickHereCommand, ClickHereExecuted));
}
public void ClickHereExecuted(object sender, ExecutedRoutedEventArgs e)
{
System.Windows.MessageBox.Show("hello");
}
}
Run Code Online (Sandbox Code Playgroud)
UserControl XAML
<UserControl x:Class="CommandBindingTest.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" x:Name="root">
<Grid DataContext="{Binding ElementName=root}" >
<Button Content="{Binding ButtonContent}" Command="{Binding ClickHereCommand}" Height="25" Width="90"></Button>
</Grid>
</UserControl> …Run Code Online (Sandbox Code Playgroud) 我在看这个问题,这让我很奇怪.
每当我定义一个具有自动属性的类时,
// Example A
public class MyObject
{
public int MyInt { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
JIT编译器将它转换为类似于:
// Example B
public class MyObject
{
private int _MyInt;
public int get_MyInt()
{
return _MyInt;
}
public void set_MyInt(int value)
{
_MyInt = value;
}
}
Run Code Online (Sandbox Code Playgroud)
所以你可以假设写下如下内容:
// Example C.1
public class MyObject
{
public int MyInt { get; set; }
public void set_MyInt(string value)
{
MyInt = int.Parse(value);
}
}
Run Code Online (Sandbox Code Playgroud)
或者像这样的东西:
// Example C.2
public class MyObject
{ …Run Code Online (Sandbox Code Playgroud) 我打开一个文件,并使用ToUniversalTime()和ToLocalTime()输出不同的时间.但是,当我使用ToFileTime()和时ToFileTimeUtc(),我得到相同的数字.为什么是这样?
DateTime creationTime = File.GetCreationTime(@"c:\windows\setupact.log");
Console.WriteLine("utc time: " + creationTime.ToUniversalTime());
Console.WriteLine("file time: " + creationTime.ToLocalTime());
Console.WriteLine("file: " + creationTime.ToFileTime());
Console.WriteLine("utc: " + creationTime.ToFileTimeUtc());
Run Code Online (Sandbox Code Playgroud)
产量
时间:2013年8月22日下午2:46:17
提交时间:2013年8月22日上午7:46:17
file:130216563774628355
utc:130216563774628355
不应该文件和utc是不同的?
我有以下(简化)代码:
public async Task GetData(DomainObject domainObject, int depth)
{
// This async operation is really quick, and there's usually like five.
IEnumerable<TierOne> tierOnes = await domainObject.GetTierOnesAsync();
var tierOneTasks = tierOnes.Select(async tierOne =>
{
// This async operation is really quick and there's usually like three.
IEnumerable<TierTwo> tierTwos = await tierOne.GetTierTwosAsync();
if (depth <= TierTwoDepth)
return;
var tierTwoTasks = tierTwos.Select(async tierTwo =>
{
// This async operation is usually fast, and there's usually >= 100.
IEnumerable<TierThree> tierThrees = await tierTwo.GetTierThreesAsync();
if …Run Code Online (Sandbox Code Playgroud) 我该如何打开新窗户?我目前正在做以下事情.
EventArgs的:
public class GenericViewRequestedEventArgs : EventArgs
{
public GenericViewModel ViewModel { get; private set; }
public GenericViewRequestedEventArgs(GenericViewModel viewModel)
{
ViewModel = viewModel;
}
}
Run Code Online (Sandbox Code Playgroud)
视图模型:
public class MainWindowViewModel : ViewModelBase
{
private RelayCommand _viewSpecificCommand;
public ICommand ViewSpecificCommand
{
get
{
if (_viewSpecificCommand == null)
_viewSpecificCommand = new RelayCommand(x => viewSpecific());
return _viewSpecificCommand;
}
}
public EventHandler<GenericViewRequestedEventArgs> GenericViewRequested;
private void RaiseGenericViewRequested(GenericViewModel viewModel)
{
var handler = GenericViewRequested;
if (handler != null)
handler(this, new GenericViewRequestedEventArgs(viewModel));
}
private void viewSpecific()
{
RaiseGenericViewRequested(_specificViewModel); …Run Code Online (Sandbox Code Playgroud) 我们可以在 git-flow 中将develop 分支合并到feature 分支中吗?
如下图所示,有 2 个功能分支(A(红色)和B(蓝色)),由两个开发人员分配。当B需要从一些代码A,将它允许是A推动发展下去编码,然后B从发展拔呢?
一个合并开发分支,没有合并而是覆盖,为什么,以及如何解决它?

我的 Angular 2 项目的 index.html 中有这些函数:
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", "teststring");
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
console.log(data);
}
</script>
Run Code Online (Sandbox Code Playgroud)
当我将这些函数放入组件中时,会出现以下错误:
Uncaught ReferenceError: drag is not defined at HTMLImageElement.ondragstart
Uncaught ReferenceError: allowDrop is not defined at HTMLDivElement.ondragover
Run Code Online (Sandbox Code Playgroud)
使用这些函数的元素在组件 html 中:
<div> ondrop="drop(event)" ondragover="allowDrop(event)">
<img> src="smiley.png" draggable="true" ondragstart="drag(event)">
</div>
<div ondrop="drop(event)" ondragover="allowDrop(event)">
</div>
Run Code Online (Sandbox Code Playgroud) 我一直在打破这个'简单的'javascript片段:
$("#hitbox").mouseleave(function() {
if($("#sub-wrapper-1").height() < 179 || $("#sub-wrapper-2").height() < 179 ) {
$("#hitbox").animate({ "height" : '0px' }, 800),
} else {
$("#hitbox").stop();
}
});
Run Code Online (Sandbox Code Playgroud)
你们能否在正确的方向上推动我如何OR在javascript中使用运算符?上面的代码不会抛出任何错误,但它似乎运行作为AND运算符的函数.
我有以下数据.
WM_Week POS_Store_Count POS_Qty POS_Sales POS_Cost
------ --------------- ------ -------- --------
201541 3965 77722 153904.67 102593.04
201542 3952 77866 154219.66 102783.12
201543 3951 70690 139967.06 94724.60
201544 3958 70773 140131.41 95543.55
201545 3958 76623 151739.31 103441.05
201546 3956 73236 145016.54 98868.60
201547 3939 64317 127368.62 86827.95
201548 3927 60762 120309.32 82028.70
Run Code Online (Sandbox Code Playgroud)
我需要写一个SQL查询来获取过去四周的数据,并总结出以下每个列的最后四周:POS_Store_Count,POS_Qty,POS_Sales,和POS_Cost.
例如,如果我想要201548的数据,它将包含201548,201547,20156和201545.
201547的总和将包含201547,201546,20155和201544.
成功运行时,查询应返回4行.
我如何制定递归查询来执行此操作?这样做有什么比递归更简单吗?
编辑:版本是Azure Sql DW,版本号为12.0.2000.Edit2:应该返回的四行将包含自己的列的总和,并且它是前三周的列.
例如,如果我想要201548的数字,它将返回以下内容:
WM_Week POS_Store_Count POS_Qty POS_Sales POS_Cost
------ --------------- ------- -------- --------
201548 15780 …Run Code Online (Sandbox Code Playgroud) 我有一个Azure Service Bus队列,我收到1到10条带有相同"密钥"的消息.其中一条消息需要使用长时间运行的操作进行处理.完成后,数据库将被更新,其他消息将检查它.但是,与此同时,其他消息将被重新排队,以便不会丢失该过程.
但重点是这个长时间运行的操作不能同时运行同一个键,不应该多次运行.
这是我到目前为止所得到的:
void Main()
{
Enumerable.Range(1, 1000)
.AsParallel()
.ForAll(async i => await ManageConcurrency(i % 2, async () => await Task.Delay(TimeSpan.FromSeconds(10))));
}
private readonly ConcurrentDictionary<int, SemaphoreSlim> _taskLocks = new ConcurrentDictionary<int, SemaphoreSlim>();
private async Task<bool> ManageConcurrency(int taskId, Func<Task> task)
{
SemaphoreSlim taskLock = null;
try
{
if (_taskLocks.TryGetValue(taskId, out taskLock))
{
if (taskLock.CurrentCount == 0)
{
Console.WriteLine($"{DateTime.Now.ToString("hh:mm:ss.ffffff")}, {taskId}, I found. No available.. Thread Id: {Thread.CurrentThread.ManagedThreadId}");
return false;
}
taskLock.Wait();
Console.WriteLine($"{DateTime.Now.ToString("hh:mm:ss.ffffff")}, {taskId}, I found and took. Thread Id: …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×2
wpf ×2
angular ×1
async-await ×1
asynchronous ×1
azure ×1
azure-sqldw ×1
datetime ×1
dom ×1
git ×1
git-flow ×1
github ×1
javascript ×1
jquery ×1
merge ×1
mvvm ×1
operators ×1
sql ×1
sql-server ×1
tpl-dataflow ×1
workflow ×1