我的应用程序是使用WPF中的MVVM模式编写的,我的所有Buttons都使用Command绑定来执行模型中的代码.所有命令都在CanExecute中具有代码,以确定绑定Button的Enabled状态.逻辑运行完美,但在所有情况下,除非我点击GUI中的其他位置,否则GUI将保持禁用状态.
例如,我有一个名为Discard Candy的按钮.当我单击此按钮时,它会在线程池线程中启动一个进程,该进程将名为Running的bool属性设置为true.由于Discard Candy命令的CanExecute方法看起来像这样
public bool CanExecute(object parameter)
{
return !Running;
}
Run Code Online (Sandbox Code Playgroud)
一旦过程开始,该按钮将被禁用.问题是当进程完成时,Running会设置为false,但GUI不会更新,即Discard Candy不会重新启用.
但是,如果我点击GUI中的任何位置,例如在窗口或标题栏上,则会立即启用Discard Candy按钮.所以逻辑是有效的,但事情正在发生,我只是不明白.有人可以向我解释一下这种行为吗?
编辑 - 到目前为止,它听起来像CommandManager.InvalidateRequerySuggested没有帮助人.我打算试一试,但此刻我有点担心.我确实按照推荐的链接,这样做决定阅读更多有关MVVM光工具包的信息.这听起来很不错 - 有没有人在这里使用它并且能够确认它没有表现出我到目前为止看到的问题?虽然我计划在下一个主要版本中尝试MVVM轻型工具包.我的应用程序,我不想重做我目前所有的命令,这就是为什么我可能会开始使用CommandManager.InvalidateRequerySuggested,所以我们都可以在这里得到另一个关于它的用处的数据点.
编辑#2 - 非常有趣,MVVM light工具包实际上依赖于CommandManager.InvalidateRequerySuggested以支持UI禁用/重新启用命令的能力.作者说:
"严格地说,在WPF中,如果你的命令绑定到CommandManager监视的控件,你不必自己引发CanExecuteChanged事件.你可以让CommandManager处理这种情况.也就是说,外部事件可能还可以改变UI的状态.假设UI应该从上午9点到下午5点启用,然后在晚上禁用.用户没有触发UI,所以代码应该(礼貌地)请求CommandManager重新查询状态命令.这是通过调用InvalidateRequerySuggested CommandManager上的方法实现的.正如你猜到了,RelayCommand类的方法RaiseCanExecuteChanged做到了这一点. "
将enabled变量声明为布尔值或布尔值是否有区别?从内存占用的角度来看,这是更可取的.
@Entity
class User {
@Column
Boolean enabled;
}
Run Code Online (Sandbox Code Playgroud) 我的商店使用TFS并且除了缺少本地存储库提交/恢复之外通常都很满意.我自己开始在本地使用Mercurial来帮助管理较小的更改块,然后将它们发布到TFS.我看到Subversion有一个'bridge'组件,如果中央VCS是Subversion,它可以自动启用它.我没有为Team System找到一个.这鼓励了我,其他人已经将DVCS与CVCS系统集成在一起.
(1)有人知道吗?我有点怀疑它(快速搜索找不到任何东西).
(2)是否有人以这种方式使用Mercurial/TFS?如果是这样,你能分享你的经历吗?我特别希望了解在通过Mercurial进行重大活动后提交给TFS的问题可能出现的问题.
到目前为止,这似乎是一个完全双赢,只有我使用了几天 - 但我知道足够的,然后认为这就是那么容易.
基本上我正在做以下事情:
std::set<int> indices;
// ..fill indices
if (flag)
{
// we need to process in ascending order
BOOST_FOREACH (int i, indices)
{
process(i);
}
}
else
{
// we need to process in descending order
BOOST_REVERSE_FOREACH (int i, indices)
{
process(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法在C++ 03中编写相同的东西,只需要调用一个进程(i),以某种方式参数化处理顺序?像这样(显然在C++ 0x中不起作用,因为begin()和rbegin()返回不同的类型):
auto iter = flag ? indices.begin() : indices.rbegin();
auto end = flag ? indices.end() : indices.rend();
BOOST_FOREACH (int i, std::make_pair(iter, end))
{
process(i);
}
Run Code Online (Sandbox Code Playgroud) Microsoft .NET 4.0为其框架引入了新的"并行增强".我想知道使用标准System.Threading函数的应用程序与新的并行增强功能之间的区别.
我正在使用我的C#教科书,它说"C#假定所有浮点文字都是double类型." 我得到了这个说法,但我不太确定如何将修复程序应用于我正在处理的示例程序.
using System;
using System.Collections.Generic;
using System.Text;
namespace CoinCounter
{
class Program
{
static void Main(string[] args)
{
int quarters;
int dimes;
int nickels;
int pennies;
float myTotal = 0F;
Console.Out.WriteLine("How many quarters are in the jar?");
quarters = int.Parse(Console.In.ReadLine());
Console.Out.WriteLine("How many dimes are in the jar?");
dimes = int.Parse(Console.In.ReadLine());
Console.Out.WriteLine("How many nickels are in the jar?");
nickels = int.Parse(Console.In.ReadLine());
Console.Out.WriteLine("How many pennies are in the jar?");
pennies = int.Parse(Console.In.ReadLine());
myTotal = (quarters * .25) + (dimes * .10) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用缓存应用程序块来缓存一些图像(这些图像需要很长时间才能渲染)
BitmapSource bitmapSource; ///some bitmap source already created
_cache /// Caching Application Block
String someId; //id for this image, used as the key for the cache
using (var stream = new MemoryStream())
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Interlace = PngInterlaceOption.On;
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(stream);
_cache.Add(someId, stream);
}
Run Code Online (Sandbox Code Playgroud)
然后使用以下方法加载它们
imStream = (Stream)_cache.GetData(someId));
if (imStream != null)
{
PngBitmapDecoder decoder = new PngBitmapDecoder(imStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0]; //return the bitmap source
}
Run Code Online (Sandbox Code Playgroud)
但在加载过程中,我在"新的PngBitmapDecoder"行中得到以下异常:
"无法访问封闭的流.
我理解我在上面的代码中关闭了流,但是在退出之前是不是_cache.Add()制作副本(通过序列化)?序列化流的正确过程是什么?
谢谢!
假设我有这两个数组:
string[] arr1 = new string[2]{"Hello", "Stack"}
string[] arr2 = new string[2]{"Stack", "Overflow"}
Run Code Online (Sandbox Code Playgroud)
我将如何把它们合并得到第三阵列像这样:string[3]{"Hello", "Stack", "Overflow"}?