我在使用XSD文件时遇到了困难.
我正在尝试从类创建一个XSD文件:
public enum Levels { Easy, Medium, Hard }
public sealed class Configuration
{
public string Name { get;set; }
public Levels Level { get; set; }
public ConfigurationSpec { get;set;}
}
public abstract class ConfigurationSpec { }
public class ConfigurationSpec1
{
// ...
}
public class ConfigurationSpec2
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
请注意,我在Configuration中有一个抽象类.有了这个功能,是否有可能创建XSD,如果可能的话?
我们的想法是将类配置传递给XSD.
这是我在局部视图中的代码
@model Contoso.MvcApplication.Models.Exercises.AbsoluteArithmetic
@using(Html.BeginForm())
{
<div>
<span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number1</span>
<span style="width: 110px; float:left; text-align:center; font-size:2.5em;">+</span>
<span style="width: 110px; float:left; text-align:center; font-size:2.5em;">@Model.Number2</span>
<span style="width: 110px; float:left; text-align:center; font-size:2.5em;">=</span>
<span>
@Html.EditorFor(model => model.Result)
@Html.ValidationMessageFor(model => model.Result)
</span>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Run Code Online (Sandbox Code Playgroud)
请注意我的代码底部,我有一个@section,我意识到如果我在那里设置一个断点,它就不会运行.如果我在_Layout.cshtml中移动该行,则效果很好,但这不是主意.
如何在部分剃刀视图中告诉MVC4我想添加该库?
我意识到.NET Framework 4.5中出现了这个界面
我首先想看看如何在Silverlight中实现(我可以想象它以相同的方式实现),但我找不到这个新界面的紧凑演示.是否可以显示我如何使用它?
我真的想找一个小的演示来理解它
我正在考虑使用EF 4开始一个新项目并浏览一些文章,我发现了一些关于EF的文章和存储库模式以及工作单元
(http://tdryan.blogspot.com/2011/03/another-entity-framework-4-repository_15.html和http://blogs.msdn.com/b/adonet/archive/2009/06/16/using -repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx)
我正在使用第一个(第1部分,第2部分和第3部分).它们非常相似.
在这种情况下,我是新手.我在这两个帖子之间感到困惑.我已经创建了所有内容,但我不知道如何开始使用上下文并添加一些实体.我发布了第二个链接,因为发布了实现它的方法.该ObjectContext来源于IUnitOfWork,所以我很困惑,以选择这两个的是更好地使用.
我正在使用JSON.NET作为我的主序列化程序.
这是我的模型,看起来我已经设置了一些JSONProperties和一个DefaultValue.
public class AssignmentContentItem
{
[JsonProperty("Id")]
public string Id { get; set; }
[JsonProperty("Qty")]
[DefaultValue(1)]
public int Quantity { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我序列化时List<AssignmentContentItem>,它做得很好:
private static JsonSerializerSettings s = new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
};
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
[{"Id":"Q0"},{"Id":"Q4"},{"Id":"Q7"}]
Run Code Online (Sandbox Code Playgroud)
但是当我想反序列化这个jsonContent时,属性Qty始终为0并且未设置为默认值.我的意思是,当我反序列化jsonContent时,因为Quantity的DefaultValue应该是1而不是0.
public static List<AssignmentContentItem> DeserializeAssignmentContent(string jsonContent)
{
return JsonConvert.DeserializeObject<List<AssignmentContentItem>>(jsonContent, s);
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办
我正在使用dataTemplate.这是模板:
<ItemsControl ItemsSource="{Binding RAM.Partitions}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Position, StringFormat={}{0}k}"/>
<Grid Grid.Column="1">
<Border>
<Border.Height>
<MultiBinding Converter="{StaticResource MultiplyConverter}">
<Binding ElementName="LayoutRoot" Path="ActualHeight"/>
<Binding Path="Size" />
<Binding Path="RAM.Size" />
</MultiBinding>
</Border.Height>
</Border>
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
你能看到这条线吗?
<Binding Path="RAM.Size" />
Run Code Online (Sandbox Code Playgroud)
该行引发了一个异常,它应该是因为RAM.Size来自父元素.我怎么能得到那个价值?
提前致谢!
我已经知道一个分数是重复小数.这是功能.
public bool IsRepeatingDecimal
{
get
{
if (Numerator % Denominator == 0)
return false;
var primes = MathAlgorithms.Primes(Denominator);
foreach (int n in primes)
{
if (n != 2 && n != 5)
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我正试图获得重复的数字.我正在查看这个网站:http://en.wikipedia.org/wiki/Repeating_decimal
public decimal RepeatingDecimal()
{
if (!IsRepeatingDecimal) throw new InvalidOperationException("The fraction is not producing repeating decimals");
int digitsToTake;
switch (Denominator)
{
case 3:
case 9: digitsToTake = 1; break;
case 11: digitsToTake = 2; break;
case 13: …Run Code Online (Sandbox Code Playgroud) 我在WPF应用程序中的后台工作者中意识到了一些奇怪的东西.
我现在想要完成的是等到BW完成另一个线程.
检查以下代码:
if (bw.IsBusy)
{
bw.CancelAsync();
System.Threading.ThreadStart WaitThread =
new System.Threading.ThreadStart(delegate() {
while (bw.IsBusy)
{
System.Threading.Thread.Sleep(100);
}
bw.RunWorkerAsync();
});
System.Windows.Application.Current.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
WaitThread); // if I remove this line, bw fires RunWorkerAsyncEvent
}
else
{
bw.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)
请注意,我添加了一个Dispatcher.Invoke,等到bw不忙,但如果我调用它并且从不触发RunWorkerAsyncCompleted事件,则所有时间都很忙.虽然,如果我删除该行,FIRES事件,这真的很奇怪.
我怎么能等到bw结束?
想象一下,在一个数据模板中,我有一个textBox和另一个数据模板,我有两个文本框.
根据这个,在视图中有一个复选框,并显示每个模板..这可能吗?
对不起,如果我的问题是如此怀疑,我已经调查了但是我没有发现.
我这样做了,我知道这没用,但仅用于测试.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T1">
<StackPanel>
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T2">
<StackPanel>
<TextBox Height="20" />
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Template="{StaticResource T1}" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 我的方案是关于开发数学问题.作为一个IProblem接口,我认为它应该包含的两个主要属性是QuestionText和Response.QuestionTextalways总是一个字符串,但Response有时可以是一个复杂的对象(一个自定义的Fractionstruc)或另一个数据类型,如string,decimal,int等.
public interface IProblem
{
string QuestionText { get; set; }
object Response { get; }
bool IsComplete();
bool IsCorrect();
}
Run Code Online (Sandbox Code Playgroud)
如你所见,Response是对象.我猜这个数据类型,因为所有问题本质上都有一个响应.因为它是一个对象,我只定义了未来的错误(投射问题).
我的想法是稍后,在具体类中访问此属性(Response),而无需强制转换.看看这个?
public abstract class Problem : IProblem
{
public string QuestionText { get; set;}
public object Response { get; protected set; }
public virtual bool IsComplete()
{
return true;
}
public abstract bool IsCorrect();
}
public class BinaryProblem : Problem
{
public …Run Code Online (Sandbox Code Playgroud) c# ×9
wpf ×4
datatemplate ×2
algorithm ×1
asp.net ×1
asp.net-mvc ×1
binding ×1
class ×1
data-binding ×1
dispatch ×1
dispatcher ×1
json.net ×1
linq-to-xsd ×1
oop ×1
razor ×1
razor-2 ×1
repository ×1
silverlight ×1
templates ×1
uml ×1
unit-of-work ×1
xaml ×1
xml ×1
xsd ×1
xsd.exe ×1