我在x86 pc上工作并在VS2010中使用.NET4.0(与3.5相同的probelem).当我创建一个新项目(例如WinFormsApp)时,我想要做的第一件事就是将项目/解决方案的目标平台更改为"任何CPU".
我做以下事情:
项目属性 - >构建 - >将TargetPlatform更改为"任何CPU"
在属性页面的顶部,平台仍然是"活动(x86)",所以我这样做
解决方案属性 - > ConfigurationsMgr - > Platform - > new(因为只有x86可用)并创建解决方案平台"Any CPU".
现在项目属性是"活动(任何CPU)",我可以随意来回更改它.
现在问题是:当我添加一个新项目时,它再次设置为"活动(x86)"并且我 - 无法 - 无法更改项目设置.在第二个项目的SolutionProperties - > ConfigurationManager中,"Any CPU"平台不可用,我无法添加新平台,因为它告诉我AnyCPU的解决方案平台已经存在......
我究竟做错了什么?将新创建的项目设置为AnyCPU会如此困难吗?
好的,我知道.这已经被问了一百万次,但我仍然没有得到它.对不起.
任务:实现最简单的依赖属性,可以在xaml中使用:
<uc:MyUserControl1 MyTextProperty="{Binding Text}"/>
Run Code Online (Sandbox Code Playgroud)
我认为这个答案非常接近.为了更好的可读性,我在这里复制了所有代码(主要来自上面的答案).
<UserControl x:Class="Test.UserControls.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<!-- Text is being bound to outward representative property;
Note the DataContext of the UserControl -->
<TextBox Text="{Binding MyTextProperty}"/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
和
public partial class MyUserControl1 : UserControl
{
// The dependency property which will be accessible on the UserControl
public static readonly DependencyProperty MyTextPropertyProperty =
DependencyProperty.Register("MyTextProperty", typeof(string), typeof(MyUserControl1), new UIPropertyMetadata(String.Empty));
public string MyTextProperty
{
get { return (string)GetValue(MyTextPropertyProperty); }
set { …Run Code Online (Sandbox Code Playgroud) 我有一个通用类型如下
public class TestGeneric<T>
{
public T Data { get; set; }
public TestGeneric(T data)
{
this.Data = data;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我现在有一个对象(来自某个外部源)我知道它的类型是一些封闭的TestGeneric <>,但我不知道TypeParameter T.现在我需要访问我的对象的数据.问题是我无法强制转换对象,因为我不确切知道哪个封闭的TestGeneric.
我用
// thx to http://stackoverflow.com/questions/457676/c-reflection-check-if-a-class-is-derived-from-a-generic-class
private static bool IsSubclassOfRawGeneric(Type rawGeneric, Type subclass)
{
while (subclass != typeof(object))
{
var cur = subclass.IsGenericType ? subclass.GetGenericTypeDefinition() : subclass;
if (rawGeneric == cur)
{
return true;
}
subclass = subclass.BaseType;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
为了确保,我的对象是泛型类型.有问题的代码如下:
public static void Main()
{
object myObject = new TestGeneric<string>("test"); // or from another …Run Code Online (Sandbox Code Playgroud) 嘿,我想使用Windows环境变量作为注册表项的值.不幸的是我不能简单地写出类似的东西%systemroot%\system32\MyScreensaver.scr.
你可以猜到,我想将一些reg值指向我自己的应用程序,例如自动启动和屏幕保护程序以及其他一些东西.
有任何想法吗?
我有一个元素列表,并希望获取总和(或任何元素的聚合)满足某个条件.以下代码完成了这项工作,但我很确定这不是一个不寻常的问题,应该存在适当的模式.
var list = new List<int> { 1, 2, 3, 4, 5, 6, 7 };
int tmp = 0;
var listWithSum = from x in list
let sum = tmp+=x
select new {x, sum};
int MAX = 10;
var result = from x in listWithSum
where x.sum < MAX
select x.x;
Run Code Online (Sandbox Code Playgroud)
有人知道如何以更好的方式解决任务,可能将TakeWhile和Aggregate合并到一个查询中吗?
谢谢
我在WindowsFormsHost中有一个Forms.DataVisualization.Charting.Chart.我无法让图表接收鼠标滚轮事件.点击工作正常,如果我尝试使用Forms.TextBox鼠标滚轮也正常工作.如果我在"原生"表单应用程序中使用图表,鼠标滚轮也可以正常工作.
那么,问题的关键是formHost中表单图表的组合.
这是一个简单的简单应用程序来复制问题:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Name="TextBlock1" Grid.Column="1" />
<WindowsFormsHost Name="WindowsFormsHost1" Grid.Column="0"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
和背后的代码:
public MainWindow()
{
InitializeComponent();
var chart = new Chart() { BackColor = System.Drawing.Color.Aquamarine};
WindowsFormsHost1.Child = chart;
chart.MouseDown += (a, b) => TextBlock1.Text += "FORMS click\r\n";
TextBlock1.MouseDown += (a, b) => TextBlock1.Text += "WPF click\r\n";
chart.MouseWheel += (a, b) => TextBlock1.Text += "FORMS wheel\r\n";
TextBlock1.MouseWheel += (a, b) => TextBlock1.Text += "WPF wheel\r\n";
}
Run Code Online (Sandbox Code Playgroud)
我可以从wpf接收所有点击和鼠标滚轮,但没有来自表单的轮子.我也试过了formHost的轮子监听器,没有成功.
有任何想法吗?Jon Skeet?
我们曾经使用Visual Studio安装项目,以及Git,TeamCity和NetSparcle来为我们的客户创建简单的部署过程以及舒适的自动更新功能。
由于我们要切换到.net4.5,因此我们不能再使用VS安装项目(不再支持),而必须切换到另一个安装程序。所以这是我对你的问题:
我读过这篇文章,但是.net4.5似乎在这里改变了游戏规则。
PS:Flexira软件非常昂贵...
deployment installer installshield setup-deployment .net-4.5
我试了整整一天才能搞定这个.我学到了很多关于EF的Fluent API的知识(例如,这是一篇优秀的文章),但是我没有成功.
我有三个实体:
public class Address
{
[Key]
public virtual int AddressId { get; set; }
public virtual string AddressString { get; set; }
}
public class User
{
[Key]
public virtual int UserId { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
}
public class House
{
[Key]
public virtual int HouseId { get; set; }
public virtual Address Address { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并尝试的所有组合HasMany, HasOptional, WithOptional, WithOptionalDependent和WithOptionalPrincipial我能为双方认为User …
c# ×4
installer ×2
wpf ×2
.net ×1
.net-4.5 ×1
aggregate ×1
binding ×1
build ×1
casting ×1
charts ×1
deployment ×1
forms ×1
generics ×1
linq ×1
mousewheel ×1
one-to-many ×1
one-to-one ×1
reflection ×1
registry ×1
xaml ×1