我有附属属性InteractionService.Triggers,属于类型TriggersCollection,源于List<ITrigger>.所以我在XAML中添加了一些触发器对象,并且每个触发器对象都实现了接口ITrigger.它工作正常,并且没有任何错误地构建.但是当我将这个库从Silverlight 5移植到Windows Phone 8并尝试将其与上述场景一起使用时,Visual Studio 2012用蓝线强调了这个XAML并告诉它存在这样的错误.当我编译项目时,错误从VS2012中的XAML消失,直到在此XAML文件中进行下一次编辑.我该如何解决这个问题?或者这是VS2012与WP8 SDK的错误?这种情况有解决方法吗?
XAML的片段(由VS2012 + WP8SDK强调,但不是由VS2010 + SL5强调):
<deToolkit:InteractionService.Triggers>
<deToolkit:EventTrigger EnterEvent="Loaded">
<deToolkit:CommandSetter Command="{Binding LoadCommand}" />
</deToolkit:EventTrigger>
</deToolkit:InteractionService.Triggers>
Run Code Online (Sandbox Code Playgroud)
TriggersCollection:
public class TriggersCollection : List<ITrigger> { }
Run Code Online (Sandbox Code Playgroud)
EventTrigger类的标题:
public class EventTrigger : TriggerBase
Run Code Online (Sandbox Code Playgroud)
TriggerBase类的标题:
public class TriggerBase : DependencyObject, ITrigger
Run Code Online (Sandbox Code Playgroud)
类InteractionService的片段:
public sealed class InteractionService : DependencyObject
{
#region [ADP] Triggers : TriggersCollection (Triggers applied to control)
public static void SetTriggers(DependencyObject element, TriggersCollection value)
{
element.SetValue(TriggersProperty, value);
}
public static …Run Code Online (Sandbox Code Playgroud) 我有一个WPF应用程序,每当我的应用程序遇到未处理的异常以帮助调试时,我需要编写一个小型转储文件.但是,每次调用异常处理程序时,堆栈都完全展开到处理程序,并且没有可用于转储文件的有用状态.
我试图订阅这两个并且堆栈已经解开了两个:
Application.Current.DispatcherUnhandledException
AppDomain.CurrentDomain.UnhandledException
Run Code Online (Sandbox Code Playgroud)
我尝试使用控制台应用程序,并且堆栈没有解开,因此它肯定与WPF相关.异常和处理程序都发生在主线程中.
这里有两个代码示例,您可以轻松地看到这一点.只需在每个处理程序中设置断点,并在遇到断点时观察调用堆栈.
控制台应用:
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
int foo = 5;
++foo;
throw new ApplicationException("blah");
++foo;
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("blah");
}
}
Run Code Online (Sandbox Code Playgroud)
WPF应用:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
int foo = 5;
++foo;
throw new ApplicationException("blah");
++foo;
base.OnStartup(e);
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {}
void Current_DispatcherUnhandledException(object …Run Code Online (Sandbox Code Playgroud) 我试图通过C#中的命名管道传递一个类对象.但是我得到一个错误"解析完成之前遇到的流结束".这真是令人沮丧,因为我设法发送字符串没有问题.有谁能看出问题是什么?
客户端发送数据:
using(NamedPipeClientStream cs =
new NamedPipeClientStream("MyServer", "MyPipeName", PipeDirection.Out, PipeOptions.Asynchronous))
{
ObservableCollection<MyObject> messageToSend = new ObservableCollection<MyObject>(new MyObject() { MyProp1 = "Hello", MyProp2 = 7 });
IFormatter f = new BinaryFormatter();
foreach (var item in messageToSend)
{
f.Serialize(pipeStream, item);
}
}
Run Code Online (Sandbox Code Playgroud)
服务器端接收数据:
NamedPipeServerStream ss = new NamedPipeServerStream("MyPipeName", PipeDirection.In);
ss.WaitForConnection();
IFormatter f = new BinaryFormatter();
MyObject messageReceived = (MyObject)f.Deserialize(cs);
Run Code Online (Sandbox Code Playgroud)
此外,当我添加到接收器时,我有另一个错误"Stream不支持搜索".
ss.Position =0;
Run Code Online (Sandbox Code Playgroud)
用作消息类型的类:
[Serializable]
public class MyObject
{
public string MyProp1 { get; set; }
public int MyProp2 { get; set; } …Run Code Online (Sandbox Code Playgroud) 我正在使用OLEDBConnection读取excel文件.我可以导入xls,xlsx和xlsm.我只读了一个合并的单元格有点问题.例如,我有合并的单元格A2,A3和A4.但在我的datagridview中,我有一个强大的A2.A3和A4是空的字符串.我怎样才能读取A3和A4的值.或者我如何在excel文件中找到合并的单元格.
我的守则
OpenFileDialog openFileDialog2;
openFileDialog2 = new OpenFileDialog();
// need to pass relative path after deploying on server
if (openFileDialog2.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string path = openFileDialog2.FileName; //récupère le chemin absolu du fichier
/* connection string to work with excel file. HDR=Yes - indicates
that the first row contains columnnames, not data. HDR=No - indicates
the opposite. "IMEX=1;" tells the driver to always read "intermixed"
(numbers, dates, strings etc) data columns as text.
Note that this option might …Run Code Online (Sandbox Code Playgroud) 我试图静态地构建C#解决方案的调用层次结构,或者换句话说,试图找出解决方案中每个方法调用的方法.
我稍微修改了另一个问题的代码片段,但它没有完全削减它:
无论何时调用基类方法,该链都会被破坏,并且该方法依次调用在子类中实现的抽象或虚方法.
var syntaxTree = SyntaxTree.ParseText(Code);
var compilation = Compilation.Create("name").AddSyntaxTrees(syntaxTree);
var semanticModel = compilation.GetSemanticModel(syntaxTree);
var methods = syntaxTree.GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>();
foreach (var method in methods)
{
var invocations = method.DescendantNodes().OfType<InvocationExpressionSyntax>();
foreach (var syntax in invocations)
Debug.WriteLine(semanticModel.GetDeclaredSymbol(method) + " calls method " +
semanticModel.GetSymbolInfo(syntax).Symbol);
}
Run Code Online (Sandbox Code Playgroud)
以下是一些示例代码来说明问题.基类方法Bar调用在C2中实现的抽象方法Baz.
class Program2
{
void Main()
{
new C2().Bar();
}
}
abstract class C1
{
public void Bar()
{
Baz();
}
public abstract void Baz();
}
class C2 : C1
{
public override void Baz() { …Run Code Online (Sandbox Code Playgroud) 我在下面使用此函数来查找两组纬度和经度对之间的距离.它似乎工作正常,但我有两个问题.它以千克而不是英里(我在美国)返回值,并且公里值似乎偏离三位小数?它返回的值是这样的:34366.7661043296这是从加利福尼亚州瓦伦西亚到加利福尼亚州伯班克约35公里的距离.为什么在公里,更重要的是为什么十进制问题?如果它只返回36.50英里之类的东西会很棒.非常感谢任何帮助,谢谢你提前.
public static double GetDistance(double sLatitude, double sLongitude, double eLatitude, double eLongitude)
{
var sCoord = new GeoCoordinate(sLatitude, sLongitude);
var eCoord = new GeoCoordinate(eLatitude, eLongitude);
return sCoord.GetDistanceTo(eCoord);
}
Run Code Online (Sandbox Code Playgroud) 我启用所有异常,并得到这个奇怪的异常:
MyApp.exe中0x773ac41f的第一次机会异常:Microsoft C++异常:内存位置0x0038c23c处的EEFileLoadException.
"System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(T));"中的问题
public T GetObjectFromFile(string fileFullPath)
{
if (System.IO.File.Exists(fileFullPath) == false)
{
return default(T);
}
System.IO.StreamReader file = new System.IO.StreamReader(fileFullPath);
try
{
System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(T));
return (T)reader.Deserialize(file);
}
catch
{
return default(T);
}
finally
{
file.Close();
}
}
Run Code Online (Sandbox Code Playgroud) 我使用MongoDB来存储可以包含可变数量的用户定义索引值的实体.每个索引都可以包含一个或多个值,因此对于用户定义的索引,我使用对象列表的字典来存储值.
public class Entity
{
public IDictionary<string, IList<object>> Indices { get; set; }
// ...
}
Run Code Online (Sandbox Code Playgroud)
我编写了一个存储库类,它支持通过传递自定义条件列表来查询实体,并且存储库构建了一个IMongoQuery使用MongoDB.Driver.Builders.Query该类的实例,并返回一个IQueryable<Entity>
public IQueryable<Entity> GetAll(IEnumerable<SearchCriterion> criteria)
{
IMongoQuery query = BuildQuery(criteria);
//https://jira.mongodb.org/browse/CSHARP-461
//return _db.GetCollection<Entity>().Find(query).AsQueryable();
return _db.GetCollection<Entity>()
.AsQueryable()
.Where(x => query.Inject());
}
Run Code Online (Sandbox Code Playgroud)
由于此处描述的问题https://jira.mongodb.org/browse/CSHARP-461我选择不使用MongoCursor.AsQueryable()因为MongoCursor实现了IEnumerable.结果是.返回时使用的任何表达式IQueryable<Entity>都不在服务器上完成,它在客户端的内存中完成.相反,我MongoCollection<T>.AsQueryable()按照建议将查询注入结果.
所以,上面的解决方案效果很好,但现在我想通过调用OrderBy()使用IMongoSortBy接口来做同样的事情来对结果进行排序,就像这样.
return _db.GetCollection<Entity>()
.AsQueryable()
.Where(x => query.Inject())
.OrderBy(x => sortBy.Inject());
Run Code Online (Sandbox Code Playgroud)
但是,IMongoSortBy接口上没有实现Inject()
如果我使用MongoCursor,这将很容易
return _db.GetCollection<Entity>()
.Find(query).
.SetSortOrder(sortBy)
.AsQueryable();
Run Code Online (Sandbox Code Playgroud)
那么,有没有办法可以使用调用对实体进行排序MongoCollection<T>.AsQueryable()?
我对Web服务很陌生.现在我使用kraken.io API来调整上传图像的大小有问题.
请求响应时,它总是抛出异常.
任何帮助表示赞赏.非常感谢你.
参考kraken.io API文档:https://kraken.io/docs/upload-url
这就是我到目前为止所做的
触发:
byte[] data = new byte[fuImage.PostedFile.ContentLength];
fuImage.PostedFile.InputStream.Read(data, 0, fuImage.PostedFile.ContentLength);
objKraken krakenio = new objKraken();
krakenio.wait = true;
krakenio.resize = new objKResize() { width = Base_Controller.DealsWidth, height = Base_Controller.DealsHeight, strategy = "exact" };
Controller_Kraken.UploadFile(data, krakenio);
Run Code Online (Sandbox Code Playgroud)
控制器:
public const string UploadAPIUrl = "https://api.kraken.io/v1/upload";
public static bool UploadFile(byte[] data, objKraken krakenInfo)
{
try
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(UploadAPIUrl);
webRequest.Method = "POST";
webRequest.ContentType = "multipart/form-data";
string jsonString = JsonConvert.SerializeObject(krakenInfo);
webRequest.ContentLength = data.Length + jsonString.Length;
using …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用Windows azure通知集线器向用户提供通知.以下是在通知中心上注册设备的API代码.
var platform = registrationCall["platform"].ToString();
var installationId = registrationCall["instId"].ToString();
var channelUri = registrationCall["channelUri"] != null ?
registrationCall["channelUri"].ToString() : null;
var deviceToken = registrationCall["deviceToken"] != null ?
registrationCall["deviceToken"].ToString() : null;
string RegistrationID = registrationCall["RegistrationID"] != null ?
registrationCall["RegistrationID"].ToString() : null;
var userName = HttpContext.Current.User.Identity.Name;
RegistrationDescription registration = null;
AppleRegistrationDescription iosExistingRegistrationByDeviceToken = null;
string UserID = User.Identity.GetUserId().ToString();
var registrationFromHub = await hubClient.GetRegistrationsByChannelAsync(deviceToken, 100);
if (registrationFromHub.Count() >= 1)
{
iosExistingRegistrationByDeviceToken =
registrationFromHub.Where(x => x.RegistrationId == RegistrationID)
.SingleOrDefault() as AppleRegistrationDescription;
}
if (iosExistingRegistrationByDeviceToken …Run Code Online (Sandbox Code Playgroud)