Tag: c#

在使用ItemsSource和帮助使用combobox之前,WPF Items集合必须为空

我的XAML是这样的,它看起来像这样: http://puu.sh/aLLrx.png http://puu.sh/aLLsQ.jpg 我的代码是: public partial class MainWindow : Window { Character aloken; Character azureKnight; Character bagiWarrior; Character incarMagician; Character segitaHunter; Character segnale; Character viciousSummoner; private List _charList = new List(); public MainWindow() { InitializeComponent(); charList.Add(new Character(“Bagi Warrior”)); this.Item = new ObservableCollection(); this.Character = new ObservableCollection(); this.DataContext = this; //Character.Add(new Character(name: “Bagi Warrior”, level: 197, […]

使用Linq to XML创建KML

大约9个月前,我在C#中创建了一组与KML 2.2元素相对应的类。 所以你可以做像myPlacemark = new Placemark(“name”); 在内部,它使用XmlDocument,XmlElement等来创建各种节点和标记。 这是一只记忆猪,可能会更快。 不,我没有使用XSD生成类。 我看到有关于使用Linq读取和解析KML的post。 但是,是否有人使用Linq to XML来创建KML? 如果没有,您认为创建程序的最佳方法是什么? 易于使用的一组类来抽象KML? 使用Linq to XML可以提高性能吗?

每次抽奖都会重绘不变的背景?

这可能是一个非常简单的问题,但我搜索并发现没有其他方法可以做到这一点。 在每个Draw上重绘背景都没有意义。 有没有办法绘制一些东西并将它们留在屏幕上? 我试图评论出来 GraphicsDevice.Clear(Color.CornflowerBlue); 但这没有用。 (它的目的是什么?)

Selenium – 带透明代理的MoveToElement()

我有元素 public ArticlePage() { PageFactory.InitElements(Browser.driver, this) } [FindsBy(How = How.Id, Using = “someId”)] private IWebElement btnTitleView { get; set; } 和行动 Actions action = new Actions(Browser.driver); action.MoveToElement(btnTitleView).Perform(); 但是当我尝试运行它时,我会收到错误 ‘System.Reflection.TargetException’对象与目标类型不匹配。 我试图通过Browser.driver.FindElement(By.Id(“someId”))找到这个元素,然后它正常工作。 因此,它存在并显示。 是否可以使用透明代理来执行Actions ? 有没有其他方法可以对透明代理执行MoveToElement()操作?

只调用一个Paint事件

我的问题是我有8个图片盒,其中只有一个是一次调用他们的绘图方法。 我的代码有点太大,所以我尽量把它缩小到受影响的部分。 我最好的猜测是,它不是我的代码中的错误,而是对绘制事件如何工作的误解。 我有一个inheritance自PictureBox的类,而不是Picturebox。 唯一的变化是构造函数 using System.Drawing; using System.Windows.Forms; public class DrawingSurface : PictureBox { public DrawingSurface(Rectangle bounds) : base() { base.Dock = DockStyle.Fill; base.SizeMode = PictureBoxSizeMode.Zoom; //I set the size and bounds which is probably redundant because //I was trying random things to fix the problem base.Size = new Size(bounds.Width, bounds.Height); base.Bounds = bounds; […]

JsonConvert.DeserializeObject特殊字符未终止字符串。 预期分隔符:

出于某种原因,当我在我的淘汰模型中有一个特殊字符并将其转换为json对象时,字符串将结束特殊字符所在的位置,并且在反序列化时出现错误: $.ajax({ url: “/Admin/Forms/Convert”, type: “post”, //contentType: “application/json”, dataType: “text”, data: “modelData=” + ko.toJSON(theModel), success: function (data) { // window.open(“/Admin/Forms/DisplayClient”); var win = getFullWindow(‘/Admin/Forms/DisplayClient’); win.open(); }, error: function (xhr, status, msg) { alert(msg); } }); 当我得到这个方法: public void Convert(string modelData) { Form form = JsonConvert.DeserializeObject(modelData); } 我收到一个错误: Unterminated string. Expected delimiter: “. Path ‘Name’, line […]

C#将通用子类型转换为父类

假设我们有以下类型: class A {} class B : A {} class X {} 为什么我们不能这样做? X var = new X(); 有没有可用的解决方法? [编辑]我试图使用协方差,但它失败了,因为我想访问X中类型为T的属性,C#不允许在接口中使用类型T: interface IX { T sth {set; get;} } class X: IX { T sth { set; get; } } [编辑2]我也尝试了这个但它失败了: class X where T : A { public T sth { set; get; } public […]

从csproj引用xproj

我在visual studio中添加了csproj到xproj引用。 我看到引用中的库和dll的路径是正确的。 Intelisens工作,但编译无法使用错误: the type could not be found. 我该如何投入使用?

特定于文化的DateTime字符串在平台之间不一致

我有一个测试应用程序,允许用户从ComboBox中选择文化,并在多行TextBox中显示特定于文化的日期。 代码如下: public partial class Form1 : Form { public Form1() { InitializeComponent(); comboBox1.Items.AddRange( CultureInfo.GetCultures(CultureTypes.SpecificCultures)); } private void comboBox1_SelectedValueChanged(object sender, EventArgs e) { CultureInfo selectedCulture = comboBox1.SelectedItem as CultureInfo; DateTime currentDate = DateTime.Now; textBox1.Text = “My Date : ” + currentDate.ToString() + Environment.NewLine + “Culture Specific Date: ” + currentDate.ToString(selectedCulture); } } 我注意到如果选择“ar-SA”,阿拉伯语(沙特阿拉伯),那么当我在不同的机器上运行应用程序时,我会看到不同的结果。 在Windows 7计算机上,文本框显示: […]

从C#中的存储过程中捕获错误

我有一个存储过程,用于在登录期间validation用户。 如果成功则返回用户实体,这样做效果很好! 我的问题是,如果它不起作用,我会在SP中引发错误,如何捕获此错误并以最佳方式使用它? 现在我得到nullrefference,这是代码:存储过程: ALTER PROCEDURE getEmployee ( @username nvarchar(50), @password nvarchar(50) ) AS DECLARE @Error_MSG nvarchar(50) BEGIN IF EXISTS (select * from Employee where eUsername = @username AND pword = @password) begin select * from Employee where eUsername = @username AND pword = @password END ELSE BEGIN SET @Error_MSG = ‘Wrong password, or user […]