我在我的第一个WPF应用程序中使用MVVM模式,并且遇到了我认为非常基本的问题.
当用户点击我视图上的"保存"按钮时,会执行一个命令,该命令在我的ViewModel中调用私有void Save().
问题是"Save()"中的代码需要一些时间来执行,所以我想在执行大块代码之前隐藏UI视图中的"保存"按钮.
问题是视图不会更新,直到所有代码都在viewmodel中执行.在执行Save()代码之前,如何强制视图重绘并处理PropertyChanged事件?
另外,我想要一种可重复使用的方式,这样我也可以轻松地在其他页面中做同样的事情.其他人已经做过这样的事了吗?一个"正在加载......"的消息?
场景:
我有这样的NavigationWindow样式:
<Style TargetType="NavigationWindow" x:Key="{x:Type NavigationWindow}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="NavigationWindow" >
...
</Style>
Run Code Online (Sandbox Code Playgroud)
我启动我的应用程序,加载一个名为Home.xaml的页面.在Home.xaml中,我有一个导航到另一个名为PersonalData的页面的按钮:
private void btnNewUser_Click(object sender, System.Windows.RoutedEventArgs e)
{
PersonalData personalData = new PersonalData();
this.NavigationService.Navigate(personalData);
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,并加载PersonalData页面.在第二页上,我有一个导航回主页的"Home"按钮:
private void btnHome_Click(object sender, System.Windows.RoutedEventArgs e)
{
Home home = new Home();
this.NavigationService.Navigate(home);
}
Run Code Online (Sandbox Code Playgroud)
我在这里使用"导航"是因为我想在以后的表单上重复使用该按钮,总是有一个通向开始页面的按钮.
所以这也有效,主页被加载.我甚至可以再次点击btnNewUser那里,PersonalData页面打开没有任何问题.
但是,当我第二次单击"主页"按钮时,出现"this.NavigationService"为空的错误.
我刚刚开始使用WPF,我不知道从哪里开始修复这个......任何人?
我正在将旧的ASP/MySql webapp更新为ASP.NET/MS SQL.
我们希望保持旧网站的登录在新应用中运行.
不幸的是,密码使用MySql的password()函数存储在MySql DB中.
是否可以在.NET或MS SQL中模拟MySql的password()函数?
任何帮助/链接表示赞赏.
官方的restangular文档提供此代码示例以在ErrorInterceptor中重试请求:
var refreshAccesstoken = function() {
var deferred = $q.defer();
// Refresh access-token logic
return deferred.promise;
};
Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
if(response.status === 403) {
refreshAccesstoken().then(function() {
// Repeat the request and then call the handlers the usual way.
$http(response.config).then(responseHandler, deferred.reject);
// Be aware that no request interceptors are called this way.
});
return false; // error handled
}
return true; // error not handled
});
Run Code Online (Sandbox Code Playgroud)
但是,正如它在评论中所说,第二次尝试不会触发任何拦截器,因为它直接使用$ http.
有没有办法让第二个请求也通过Restangular管道并执行ErrorInterceptor?
在css类"employee_mouseover"中,我将bg颜色设置为红色.
$(".employee").bind("mouseenter", function() {
$(this).addClass("employee_mouseover");
});
$(".employee").bind("mouseleave", function() {
$(this).removeClass("employee_mouseover");
});
Run Code Online (Sandbox Code Playgroud)
这很好用.
但是,当我设置一个速度让它看起来更漂亮时,当我快速做一个mouseenter + mouseleave时,该元素会保持红色;
$(".employee").bind("mouseenter", function() {
$(this).addClass("employee_mouseover", "fast");
});
$(".employee").bind("mouseleave", function() {
$(this).removeClass("employee_mouseover", "fast");
});
Run Code Online (Sandbox Code Playgroud)
除非我非常缓慢地移入和移出元素,否则这不会很好.
有一个更好的方法吗?
提前致谢.
我已经看到一些使用'T'的样本来使一个方法可以重用于不同类的泛型集合,但我从来没有真正深入到它或理解样本.
我想知道是否有可能将下面的两种方法合二为一,这样做的缺点是(性能方面).
任何人?
[NonAction]
public List<SelectListItem> ToSelectList(IEnumerable<Department> departments, string defaultOption)
{
var items = departments.Select(d => new SelectListItem() { Text = d.Code + " - " + d.Description, Value = d.Id.ToString() }).ToList();
items.Insert(0, new SelectListItem() { Text = defaultOption, Value = "-1" });
return items;
}
[NonAction]
public List<SelectListItem> ToSelectList(IEnumerable<Function> functions, string defaultOption)
{
var items = functions.Select(f => new SelectListItem() { Text = f.Description, Value = f.Id.ToString() }).ToList();
items.Insert(0, new SelectListItem() { Text = defaultOption, Value = "-1" }); …Run Code Online (Sandbox Code Playgroud) 我在webapp上有以下情况:
表"Employees"包含" Department "和" Function "列.两者都是下拉列表.
"功能"下拉列表选项取决于所选的"部门".(所以每个部门都有自己的功能列表)
更改部门时,我使用参数"DepartmentId"对控制器操作执行ajax调用.控制分数上有一个[outputcache]属性,因此它返回的函数将被缓存为每个部门ID.
我的问题是页面的初始加载. 你能在视图中调用控制权并利用缓存吗?
任何人?30次观看,没有答案..关于我的问题的任何评论?太明显了?太难?太奇怪了?谷歌的东西(虽然我没有在那里找到解决方案)?
如何以编程方式设置按钮的模板?
Polygon buttonPolygon = new Polygon();
buttonPolygon.Points = buttonPointCollection;
buttonPolygon.Stroke = Brushes.Yellow;
buttonPolygon.StrokeThickness = 2;
// create ControlTemplate based on polygon
ControlTemplate template = new ControlTemplate();
template.Childeren.Add(buttonPolygon); // This does not work! What's the right way?
//create button based on controltemplate
Button button = new Button();
button.Template = template;
Run Code Online (Sandbox Code Playgroud)
所以我需要一种方法将我的Polygon设置为按钮的模板.建议?
谢谢.
[TDD新手]
我有一辆带有颜色和品牌属性的汽车.
在TDD中测试构造函数是否设置了这些属性是否有意义?或者我等待测试(并实施)直到我需要它?
那么,我是否构建了这样的测试:
(C#)
public class CarTests
{
public void Constructor_Should_Set_Color()
{
var car = new Car("Green", "Volvo");
Assert.Equals(car.Color, "Green");
}
}
Run Code Online (Sandbox Code Playgroud)
或者我等到我有一个用例场景,例如,我必须从使用构造函数构建的列表中筛选所有绿色汽车,这将失败,因为汽车将为null作为颜色?
直接测试构造函数真的有意义吗?怎么样Equals()?
我正在尝试使用以下ID访问MS CRM 2011中的元素:account | NoRelationship | Form | B_GenerateInvoice-Large
我可以在IE开发人员工具中看到这个元素:

不幸的是,我总是在尝试找到这个元素时得到null.
我尝试过以下方法:
alert(document.getElementById('account|NoRelationship|Form|B_GenerateInvoice-Large'));
alert($("[id='account|NoRelationship|Form|B_GenerateInvoice-Large]").html());
alert($(jq("account|NoRelationship|Form|B_GenerateInvoice-Large")).html()); // jq() adds the '#' and escapes special characters
alert($("#account|NoRelationship|Form|B_GenerateInvoice-Large").html());
alert(document.getElementById("#account\\|NoRelationship\\|Form\\|B_GenerateInvoice-Large"));
alert($("#account\\|NoRelationship\\|Form\\|B_GenerateInvoice-Large").html());
Run Code Online (Sandbox Code Playgroud)
这些都找不到元素.
我错过了一些明显的东西吗?
解:
javascript在iframe中,而元素在iframe之外.
我没有设法解决它.
wpf ×3
.net ×2
c# ×2
jquery ×2
angularjs ×1
asp.net-mvc ×1
caching ×1
code-behind ×1
encryption ×1
generics ×1
javascript ×1
jquery-ui ×1
mvvm ×1
mysql ×1
navigation ×1
refactoring ×1
restangular ×1
sql ×1
sql-server ×1
tdd ×1
unit-testing ×1