我拥有的是具有IsReadOnly属性的对象.如果此属性为true,我想将IsEnabledButton(例如)上的属性设置为false.
我想相信我可以轻松地做到这一点,IsEnabled="{Binding Path=!IsReadOnly}"但不能与WPF一起使用.
我不得不经历所有的风格设置吗?对于像将一个bool设置为另一个bool的反向那样简单的事情,似乎太过冗长.
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsReadOnly}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsReadOnly}" Value="False">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
Run Code Online (Sandbox Code Playgroud) 我想知道某个类的C#扩展方法是否可以作为接口的实现?我有什么:
一个表面:
public interface IEventHandler
{
void Notify(SEvent ev, IEventEmmiter source);
}
Run Code Online (Sandbox Code Playgroud)
实现它的类:
class Sim : IEventHandler
{
/*public void Notify(SEvent ev, IEventEmmiter source)
{
Console.WriteLine("Got notified: " + ev.Name);
}*/
}
Run Code Online (Sandbox Code Playgroud)
还有一个包含扩展方法的类:
public static class ReflectiveEventDispatcher
{
public static void Notify(this IEventHandler handler, SEvent ev)
{
if (handler.GetType().GetMethod("Handle" + ev.Name) != null)
{
// C# WTF?
object[] prms = new object[0];
prms[0] = ev;
handler.GetType().GetMethod("Handle" + ev.Name).Invoke(handler, prms);
}
else
{
throw new System.NotImplementedException("This object doesn't have appropriate handler …Run Code Online (Sandbox Code Playgroud) 看看新的C#7.0 ValueTuples,我想知道它们是否会完全取代Anonymous Types.我知道这ValueTuples是结构,因此行为与Anonymous Types类不同.但是,我没有看到一个用例,我更喜欢使用Anonymous Typeover ValueTuple.
是否存在使用a Anonymous Type仍然比ValueTuples在C#7.0中使用更有用的用例?
我想区分以编程方式更改文本(例如在按钮单击处理程序事件中)和用户输入(键入,剪切和粘贴文本).
可能吗?
无法分配"AppendText",因为它是"方法组".
public partial class Form1 : Form
{
String text = "";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String inches = textBox1.Text;
text = ConvertToFeet(inches) + ConvertToYards(inches);
textBox2.AppendText = text;
}
private String ConvertToFeet(String inches)
{
int feet = Convert.ToInt32(inches) / 12;
int leftoverInches = Convert.ToInt32(inches) % 12;
return (feet + " feet and " + leftoverInches + " inches." + " \n");
}
private String ConvertToYards(String inches)
{
int yards = Convert.ToInt32(inches) / …Run Code Online (Sandbox Code Playgroud) 我为我的Slider启用了IsMoveToPointEnabled,所以当我单击组件上的任何位置时,选择器会移动到我的鼠标.问题是如果我打开此选项并单击并按住鼠标以拖动选择器,选择器不会移动.有人知道怎么修这个东西吗?
我遇到了一些奇怪/意外的行为,其中Guid.ToString()Linq表达式返回的结果与Guid.ToString()foreach循环中的结果不同.
方法是做什么的:
有问题的方法是简单地获取一个对象,然后从原始对象创建一个新的视图模型.我工作的公司已经决定不允许在视图模型上使用Guid,因为我们的一个较旧的JSON序列化程序有一个错误,其中Guid没有正确序列化.
问题/意外结果:
在调试/测试我的方法时,我发现我创建的Linq表达式返回了一个奇怪的结果.将我的Guid转换为其字符串表示形式时,结果会自动大写.我一开始并不认为这是Linq表达式,但是一旦我将逻辑转换为foreach循环,我得到了一个较低的字符串表示我的Guid.
示例代码:
请注意,lookupList(ID1,ID2,ID3)的属性类型都是Guid类型,NewClass上的属性都是string类型.
Linq表达:
List<NewClass> returnList = lookupList.Select(i => new NewClass {
Property1 = i.ID1.ToString(),
Property2 = i.ID2.ToString(),
Property3 = i.ID3.ToString(),
.....
}).ToList();
Run Code Online (Sandbox Code Playgroud)
返回:
{
Property1=7081C549-64D6-458E-A693-0D2C9C47D183
Property2=06DD6A59-D339-4E15-89EA-48803DBA271E
Property3=9A876EDD-3B79-C27E-1680-E0820A0CD6EC
}
Run Code Online (Sandbox Code Playgroud)
Foreach循环:
var returnList = new List<NewClass>();
foreach (var item in lookupList)
{
returnList.Add(new NewClass
{
Property1 = item.ID1.ToString(),
Property2 = item.ID2.ToString(),
Property3 = item.ID3.ToString(),
.....
});
}
Run Code Online (Sandbox Code Playgroud)
返回:
{
Property1=7081c549-64d6-458e-a693-0d2c9c47d183
Property2=06dd6a59-d339-4e15-89ea-48803dba271e
Property3=9a876edd-3b79-c27e-1680-e0820a0cd6ec
}
Run Code Online (Sandbox Code Playgroud)
问题:
为什么会发生这种情况并且是预期的行为?我希望Linq表达式和foreach循环在.ToString()应用于我的Guid 时返回相同的结果,但不知何故它不是.我还检查.ToString() …
在WPF中,您可以创建一个Style充当XAML中控件类型的默认值:
<Style TargetType="{x:Type local:MyControl}">
. . .
</Style>
Run Code Online (Sandbox Code Playgroud)
然后,当WPF显示该控件时,它会Style根据其类型从资源中查找该控件.
我想在我的程序的代码隐藏中做相同的操作.我怎么找到的Style?
Entity Framework Core 引入了HasServiceTier和HasPerformanceLevel方法来更改 Azure SQL 服务器的版本。您可以像这样在OnModelCreating 中使用它们:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasServiceTier("Basic");
modelBuilder.HasPerformanceLevel("Basic");
}
Run Code Online (Sandbox Code Playgroud)
如果你使用 Add-Migration Add-Migration你会得到这样的迁移:
public partial class ChangedDatabaseServiceTierToBasic : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("SqlServer:EditionOptions", "EDITION = 'Basic', SERVICE_OBJECTIVE = 'Basic'");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.OldAnnotation("SqlServer:EditionOptions", "EDITION = 'Basic', SERVICE_OBJECTIVE = 'Basic'");
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,但是当我出于开发目的尝试将此迁移应用于本地非 Azure 数据库时,我收到以下错误:
Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20200413102908_ChangedDatabaseServiceTierToBasic'.
Applying migration '20200413102908_ChangedDatabaseServiceTierToBasic'.
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用xUnit.net进行单元测试.我想用'[InlineData]'进行'理论'测试,其中包括'小数':
[Theory]
[InlineData(37.60M)]
public void MyDecimalTest(decimal number)
{
Assert.Equal(number, 37.60M);
}
Run Code Online (Sandbox Code Playgroud)
这是不可能的,因为您不能将小数创建为常量.我找到了解决方法,把数引号 LIK如此__CODE__.这实际上会将其转换为双重,这将使测试失败.
问题:
有解决方法吗?如果不是,为我的测试创建多个测试用例的最简单方法是什么?