在WPF中,ComboBox没有SelectedText属性.
有没有办法实现与TextBox SelectedText在WPF中相同的功能
这是我的功能.
如果将MemoryStream传递给XmlReader,它有时不会验证正确的xml文件.我将XmlDocument对象存储在内存中,我想根据最终用户提供的xsd Schema文件对其进行验证.
ValidateSchema1(string XMLPath, string XSDPath)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(XMLPath);
using (MemoryStream mstream = new MemoryStream())
{
//StreamWriter writer = new StreamWriter(mstream);
xmlDocument.Save(mstream);
mstream.Seek(0, SeekOrigin.Begin);
XmlSchemaSet sc = new XmlSchemaSet();
// Add the schema to the collection.
sc.Add(null, XSDPath);
// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ValidationEventHandler += ValidationCallBack;
// Create the XmlReader object.
// Not woking
XmlReader reader = XmlReader.Create(mstream, settings);
// Working
//XmlReader reader = …Run Code Online (Sandbox Code Playgroud) 我正在编写一种使用新的ReadAsync方法读取大文件的方法.在我的测试看起来像FileStream ReadAsync比StreamReader更快,不知道为什么?
线程ID在等待之前:9
等待后的线程ID:13
时间:76626
总字节数:687184052
线程ID在等待之前:9
等待后的线程ID:10
时间:19167
总字节数:687184052
static async Task<long> ReadStreamReaderAsync(string filename)
{
Console.WriteLine("Thread ID Before Await : {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
long totalBytes = 0;
var sp = new Stopwatch();
sp.Start();
using (StreamReader reader = new StreamReader(filename, Encoding.Default))
{
char[] buffer = new char[0x1000];
int numRead;
while ((numRead = await reader.ReadAsync(buffer, 0, buffer.Length)) != 0)
{
totalBytes += numRead;
}
}
sp.Stop();
Console.WriteLine("Thread ID After Await : {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("Time : {0}", sp.ElapsedMilliseconds);
return totalBytes;
} …Run Code Online (Sandbox Code Playgroud)