我有一个TextBlock,绑定了一个Object,当我更新对象的属性时,它没有在UI上重新发布,为什么?
码:
<TextBlock Name="txtName" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" Width="100" Height="20" Margin="12,23,166,218" />
Run Code Online (Sandbox Code Playgroud)
public partial class Window1 : Window
{
Employee obj ;
public Window1()
{
InitializeComponent();
obj = new Employee();
obj.Name = "First";
txtName.DataContext = obj;
}
private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
obj.Name = "changed";
}
}
public class Employee : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
public string Name
{
set
{
this._name = value;
OnPropertyChanged(Name);
}
get { return this._name; }
} …Run Code Online (Sandbox Code Playgroud) 我们需要在一些逻辑中迭代模型的属性以自动绑定属性,并希望扩展功能以在C#4.0中包含新的数据注释.
目前,我基本上遍历所有ValidationAttribute实例中的每个属性加载并尝试使用Validate/IsValid函数进行验证,但这似乎对我没有用.
作为一个例子,我有一个模型,如:
public class HobbyModel
{
[Required(AllowEmptyStrings = false, ErrorMessage = "Do not allow empty strings")]
[DisplayName("Hobby")]
[DataType(DataType.Text)]
public string Hobby
{
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
检查属性的代码是:
object[] attributes = propertyInfo.GetCustomAttributes(true);
TypeConverter typeConverter =
TypeDescriptor.GetConverter(typeof(ValidationAttribute));
bool isValid = false;
foreach (object attr in attributes)
{
ValidationAttribute attrib = attr as ValidationAttribute;
if (attrib != null)
{
attrib.Validate(obj, propertyInfo.Name);
}
}
Run Code Online (Sandbox Code Playgroud)
我调试了代码,模型确实有3个属性,其中2个是从ValidationAttribute派生的,但是当代码通过Validate函数(带有空值或空值)时,它会按预期抛出异常.
我期待我做一些愚蠢的事情,所以我想知道是否有人使用过这个功能并且可以提供帮助.
先谢谢,杰米
asp.net modelstate validationattribute data-annotations asp.net-mvc-3
我有一个简短的程序,它将字符串转换为简单字符串的日期和时间格式.
但是,由于字符串的顺序,系统似乎无法将字符串转换为日期时间格式.应该转换的字符串就像一个例子:"Thu Dec 9 05:12:42 2010"
该方法Convert.ToDateTime已被使用但不起作用.
有人可以告知代码吗?谢谢!
String re = "Thu Dec 9 05:12:42 2010";
DateTime time = Convert.ToDateTime(re);
Console.WriteLine(time.ToString("dddd, dd MMMM yyyy HH:mm:ss"));
Run Code Online (Sandbox Code Playgroud) 我们有一个大约20列的表,如下所示:
我们需要插入1000条记录,稍后再选择也会产生大约1000条记录.
尝试以两种方式完成插入:
两种情况下的插入都需要30秒以上.我们甚至尝试在干净的桌子上做这件事.怎么加速呢?
[对于普通的10列表,我们已经通过parallel.for在大约60秒内完成了200万条记录插入.]
选择(从SQL mgmt studio测试)返回2000条记录也需要超过30秒,即使在干净的表格中也是如此.
时间可变:
可变大小或上限固定大小会在列中产生很大差异VARCHAR(SIZE)吗?
[磁盘速度很快(RAID?不确定)并专用于此数据库]
表模式:(没有PK)
varchar(50)
varchar(2)
smallint
varchar(2048)
int
int
varchar(2048)
varchar(MAX)
varchar(MAX)
varchar(MAX)
smallint
varchar(500)
varchar(500)
varchar(MAX)
smallint
smallint
bigint
bigint
bigint
varchar(2048)
smallint
varchar(MAX)
varchar(MAX)
varchar(2048)
datetime
Run Code Online (Sandbox Code Playgroud)
指数:
索引在varchar(50)上,非唯一非群集
SELECT语句:
select *
from table
where varchar(50) = 'value1'
and varchar(2) = 'value2'
and smallint = 'value3'
Run Code Online (Sandbox Code Playgroud)
每个组合varchar(50)都有5个唯一varchar(2)条目,每个条目有varchar(2)1-3 smallint个条目.
这可能是Bundler上一个非常"新手"的问题,但我想知道bundle install如何知道使用什么环境或如何设置它?或者我甚至需要?我的问题是我按环境分组我的宝石(在Gemfile中),现在部署我只想安装生产宝石.
我正在使用firebug页面速度实用程序,其中一个建议是压缩图像 - 所以我编写了以下代码来压缩图像
$filename="http://localhost.com/snapshots/picture.png";
$img = imagecreatefrompng($filename);
$this->_response->setHeader('Content-Type', 'image/png');
imagepng($img,null,9);
imagedestroy($img);
现在实际的图像尺寸是154K所以我通过给出不同的质量水平进行实验,这就是我发现的
imagepng($img,null,0); --> Size = 225K imagepng($img,null,1); --> Size = 85.9K imagepng($img,null,2); --> Size = 83.7K imagepng($img,null,3); --> Size = 80.9K imagepng($img,null,4); --> Size = 74.6K imagepng($img,null,5); --> Size = 73.8K imagepng($img,null,6); --> Size = 73K imagepng($img,null,7); --> Size = 72.4K imagepng($img,null,8); --> Size = 71K imagepng($img,null,9); --> Size = 70.6K
这些结果看起来是否准确 - 我不确定质量为0的原因 - 图像尺寸大于实际尺寸.
其次,这是PHP在压缩图像之前压缩图像以提高性能的最佳方式.
基于这些建议,最好在保存时压缩图像一次 - 我挖掘了闪存程序调用的代码以生成快照 -
$video = $this->_getParam('video');
$imgContent = … 我正在开发一个Web应用程序,它涉及创建各种列表中的餐馆列表,例如"Joe必须访问的地方".现在为每个餐厅和列表,我在网站上显示计算
目前我在PHP中使用MySQL语句,但计划切换到MySQL VIEWS并在PHP中执行简单的select语句...
我的问题是, 使用VIEWS而不是在PHP中编写SQL查询有什么优点/缺点?
我收到以下错误:
error C3646: 'closure' : unknown override specifier
Run Code Online (Sandbox Code Playgroud)
代码:
void BaseOperator::mousebutton_cb(EventObject* sender, EventArgs* calldata, void* closure)
{
xd3D::Operation::Operator::BaseOperator* operator = (xd3D::Operation::Operator::BaseOperator*)closure;
MouseButtonEventArgs* e = (MouseButtonEventArgs*)calldata;
if (e->Status == Down)
operator->OnMouseButtonDown(e);
else
operator->OnMouseButtonUp(e);
}
Run Code Online (Sandbox Code Playgroud)
你知道为什么我有这个错误吗?
php ×3
android ×1
api ×1
architecture ×1
asp.net ×1
binding ×1
bundler ×1
c# ×1
c++ ×1
datetime ×1
modelstate ×1
mysql ×1
overriding ×1
performance ×1
specifier ×1
sql ×1
sql-server ×1
wpf ×1