我有一个数据验证ViewModel.当我加载时View,检查验证而不更改其内容,这TextBox意味着通过加载视图将错误样式设置为TextBox
这是代码:
XAML
<TextBox {...} Text="{Binding Path=ProductName,
UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True}"/>
Run Code Online (Sandbox Code Playgroud)
在ViewModel,使用数据注释进行验证:
Code
private string _productName;
[Required(AllowEmptyStrings = false, ErrorMessage = "The Product Name can't be null or empty.")]
[StringLength(50, ErrorMessage = "The Product Name can't be longer than 50.")]
[Uniqueness(Entities.Product, ErrorMessage = "A Product with that Name already exists ")]
public string ProductName
{
get { return _productName; }
set
{
_productName = value;
SaveProduct.OnCanExecuteChanged();
OnPropertyChanged("ProductName");
}
}
Run Code Online (Sandbox Code Playgroud)
如何加载视图时如何停止验证触发?
我不希望在TextBox插入数据之前显示错误.
我有以下代码用python 2.7编写
# -*- coding: utf-8 -*-
import sys
_string = "años luz detrás"
print _string.encode("utf-8")
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
print _string.encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
任何帮助表示感谢,提前谢谢
我有这个xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:My.Windows"
>
<ObjectDataProvider x:Key="TitledWindow_Test" MethodName="Test" ObjectInstance={x:Type l:TitledWindow}">
<ControlTemplate x:Key="TitledWindowControlTemplateKey" x:Name="PART_ControlTemplate" TargetType="{x:Type l:TitledWindow}"
<Rectangle>
<Rectangle.Style>
<EventSetter Event="Mouse.MouseEnter" Handler="{StaticResource TitledWindow_Test}">
</Rectangle.Style>
</Rectangle>
</ControlTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
我的c#代码:
namespace My.Windows
{
public partial class TitledWindow : Window
{
public void Test()
{
MessageBox.Show("Test");
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我收到以下错误:
错误1
"ResourceDictionary"根元素需要ax:Class属性来支持XAML文件中的事件处理程序.删除MouseEnter事件的事件处理程序,或将ax:Class属性添加到根元素.