我很难找出依赖属性的正当理由.为什么System.Controls.TextBox"Text"属性是依赖属性而不是普通属性?作为依赖财产有什么好处?
我想要完成的一件事是向我的UserControl添加一个ValidationRules属性,该属性将包含其他验证规则.像这儿:
<customControls:RequiredTextBox.ValidationRules>
<validators:NotNullOrEmptyValidationRule ErrorMessage="FirstName cannot be null or empty"/>
</customControls:RequiredTextBox.ValidationRules>
Run Code Online (Sandbox Code Playgroud)
问题是我不确定ValidationRules属性是DependencyProperty还是普通属性.
上面的代码给出了以下错误:
{"Cannot add element to 'ValidationRules'; the property value is null. Error at object 'LearningWPF.ValidationRules.NotNullOrEmptyValidationRule' in markup file 'LearningWPF;component/addcustomerwindow.xaml' Line 35 Position 66."}
Run Code Online (Sandbox Code Playgroud)
这是ValidationRules属性:
public static readonly DependencyProperty ValidationRulesProperty =
DependencyProperty.Register("ValidationRules",
typeof (Collection<ValidationRule>), typeof (RequiredTextBox),
new FrameworkPropertyMetadata(null));
public Collection<ValidationRule> ValidationRules
{
get { return (Collection<ValidationRule>)GetValue(ValidationRulesProperty); }
set { SetValue(ValidationRulesProperty, value); }
}
Run Code Online (Sandbox Code Playgroud) 我正在检查ASP.NET 4.0中的OutputCacheProvider并使用它将我的输出缓存存储到MongoDb数据库中.我无法理解Add方法的目的,它是OutputCacheProvider的覆盖方法之一.将VaryByParam设置为某个值时,将调用Add方法.所以,如果我有VaryByParam ="id",那么将调用Add方法.
但是在调用Add the Set之后我也可以在Set方法中插入MongoDb数据库.
public override void Set(string key, object entry, DateTime utcExpiry)
{
// if there is something in the query use the path and query to generate the key
var url = HttpContext.Current.Request.Url;
if (!String.IsNullOrEmpty(url.Query))
{
key = url.PathAndQuery;
}
Debug.WriteLine("Set(" + key + "," + entry + "," + utcExpiry + ")");
_service.Set(
new CacheItem() { Key = MD5(key), Item = entry, Expires = utcExpiry }
);
}
Run Code Online (Sandbox Code Playgroud)
在Set方法中,我使用PathAndQuery获取QueryString的参数,然后在密钥上执行MD5并将其保存到MongoDb数据库中.
如果我正在做类似VaryByParam ="custom"之类的东西,似乎Add方法会很有用.
任何人都可以对OutputCacheProvider的Add方法有所了解吗?
我正在尝试使用DotNetOpenId库在测试网站上添加OpenID支持.出于某种原因,它在Firefox上运行时一直给我以下错误.请记住,我正在使用localhost,因为我正在本地计算机上测试它.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;
namespace TableSorterDemo
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var openid = new OpenIdRelyingParty();
if (openid.GetResponse() != null)
{
switch (openid.GetResponse().Status)
{
case AuthenticationStatus.Authenticated:
var fetch = openid.GetResponse().GetExtension(typeof(ClaimsResponse)) as ClaimsResponse;
var nick = fetch.Nickname;
var email = fetch.Email;
break;
}
}
}
protected void OpenIdLogin1_LoggedIn(object sender, OpenIdEventArgs e)
{
var openid = new …
Run Code Online (Sandbox Code Playgroud) 我如何使用 UICollectionView 创建一个电子表格,如布局,其中每行显示单个对象的属性。
例子:
Customer Id First Name Last Name Social Address Phone
Run Code Online (Sandbox Code Playgroud)
这是我想出的使用 UITableView 的方法:
funds = [[NSMutableArray alloc] init];
columnNames = [NSArray arrayWithObjects:@"fundNumber",@"fundName",@"unitPrice",@"fundBalance",@"percentageOfAccountValue",@"futureContributionAllocation", nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FundCell"];
Fund *fund = [funds objectAtIndex:[indexPath row]];
for(NSString *columnName in columnNames)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(x, 0, 100, 44)];
label.backgroundColor = [UIColor clearColor];
label.text = [fund valueForKey:columnName];
x += label.bounds.size.width;
[cell addSubview:label];
}
x = 0;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
这可能是一个有趣的问题.如果我能成功上传并获取PDF文件,我需要测试一下.这适用于基于文本的文件,但我只是想检查PDF.要运行此单元测试,我需要一个PDF文件.有几种选择.我可以创建一个虚拟PDF文件并将其存储在一些文件夹中并读取该文件并将文件保存到系统中.但现在,我的单元测试依赖于PDF文件.因此,运行单元测试的任何人都必须拥有有点不好的PDF文件.
另一种方法是创建一个PDF文件.这不是什么大问题,因为我可以简单地创建一个带有.pdf扩展名的虚拟文件,或者我甚至可以使用一些PDF第三方工具来创建PDF文件.
另一种方法是将PDF文档作为嵌入资源嵌入,然后从程序集中提取.
您认为处理此问题的最佳方法是什么?
我试图用纬度和经度找到以英里为单位的距离.我有以下方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if(!newLocation) return;
if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
(oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
{
CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude];
CLLocationDistance distance = ([loc2 distanceFromLocation:loc1]) * 0.000621371192;
//distance = distance;
NSLog(@"Total Distance %f in miles",distance);
}
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它打印出类似5678.32英里的东西.这个位置非常固定,根本不动.
我试图从核心数据中获取一个实体,具体取决于名为"name"的属性.这是我的代码:
NSManagedObjectContext *context = [self managedObjectContext];
NSEntityDescription *vegetable = [NSEntityDescription insertNewObjectForEntityForName:@"Vegetable" inManagedObjectContext:context];
// get the vegetable using name
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"name == %@", myGardenViewModel.vegetable.name];
[request setEntity:vegetable];
[request setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:request error:&error];
Run Code Online (Sandbox Code Playgroud)
最后一行抛出以下异常:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Vegetable subentitiesByName]: unrecognized selector sent to instance 0x6bbcdd0'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我使用以下代码来调用http://www.highoncoding.com/Customers.asmx Web服务.
更新1:
现在,我有以下代码:
-(NSMutableArray *) getAll
{
NSURL *baseURL = [NSURL URLWithString:@"http://highoncoding.com/Customers.asmx?op=GetAll"];
NSString *soapBody = @"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body> <GetAll xmlns=\"http://tempuri.org/\" /></soap:Body></soap:Envelope>";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL];
[request setHTTPBody:[soapBody dataUsingEncoding:NSUTF8StringEncoding]];
[request addValue:@"http://tempuri.org/GetAll" forHTTPHeaderField:@"SOAPAction"];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation start];
Run Code Online (Sandbox Code Playgroud)
但它不是返回XML而是返回HTML/CSS.
更新2:
我错过了httpMethod行:
[request setHTTPMethod:@"POST"];
Run Code Online (Sandbox Code Playgroud)