我有一个用户权限的枚举类型,如下所示:
[Flags]
public enum UserPrivileges : byte
{
None = 0, // 0000 0000
View = 1 << 0, // 0000 0001
Import = 1 << 1, // 0000 0010
Export = 1 << 2, // 0000 0100
Supervisor = View | Import | Export | 1 << 3, // 0000 1111
Admin = Supervisor | 1 << 4 // 0001 1111
}
Run Code Online (Sandbox Code Playgroud)
这些值通过值转换器绑定到GUI中的CheckBoxes.(我希望这样做尽可能通用,因为还有不同的权限[例如EmployeePrivileges])
public class ByteFlagsEnumValueConverter : IValueConverter
{
private byte _targetValue;
public object Convert(object value, Type targetType,
object …Run Code Online (Sandbox Code Playgroud) 你可以点击它们来选择md-chip元素md-chips,但我还没有找到一个好的方法来找出在控制器中选择了哪一个.
有没有人完成这个?
<md-chips ng-model="ctrl.roFruitNames">
<md-chip-template>
<strong>{{$chip}}</strong>
<em>(fruit)</em>
</md-chip-template>
</md-chips>
Run Code Online (Sandbox Code Playgroud)
我有一个ListBox用ListBoxItems一个模板,以便它们包含TextBoxes

当TextBox聚焦时我希望ListBoxItem被选中.我发现的一个解决方案如下:
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
这很有效,但是当TextBox失去焦点时,选择也是如此.
有没有办法防止这种情况发生?
我正在尝试将以前通过Excel工作表提供的一些功能实现到C#应用程序中,但Accord.NET的概率质量功能由于某种原因与excel功能不同.
在Excel中probabilty群发功能,使用这种方法
=BINOM.DIST(250; 3779; 0.0638; FALSE)
Result: 0.021944019794458
Run Code Online (Sandbox Code Playgroud)
当我尝试使用Accord.NET时
var binom = new BinomialDistribution(3779, 0.0638);
binom.ProbabilityMassFunction(250);
// Result: Infinity
Run Code Online (Sandbox Code Playgroud)
但累积分布似乎正常工作(除了最后几位数,但我认为这只是某种精度误差)
Excel中:
=BINOM.DIST(250; 3779; 0.0638; TRUE)
Result: 0.736156366002849
Run Code Online (Sandbox Code Playgroud)
Accord.NET:
var binom = new BinomialDistribution(3779, 0.0638);
binom.DistributionFunction(250);
// Result: 0.736156366002318
Run Code Online (Sandbox Code Playgroud)
为什么结果如此不同?有没有办法通过Accord获得Excel结果?
编辑: Extreme.Numerics计算与Excel相同的结果,但我不想使用此库,因为此库的许可证系统在过去总是导致麻烦.
编辑2:似乎某种溢出错误.
当我使用它时,我得到了正确的结果:
Math.Exp(binom.LogProbabilityMassFunction(250));
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会发生这种情况?
我正在尝试实现一个非常简单的自定义表单控件。
@Component({
selector: 'text-input',
template: '<input [(ngModel)]="value" />',
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TextInputComponent),
multi: true
}]
})
export class TextInputComponent implements ControlValueAccessor {
private _value: any;
get value(): any { return this._value; }
set value(value: any) { return this.writeValue(value); }
writeValue(value: any) {
if (value !== this._value) {
this._value = value;
this.onChange(value);
}
}
onChange = (x: any) => { };
onTouched = () => { };
registerOnChange(fn: (_: any) => void): void { this.onChange = fn; …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试index.html使用 .NET Core 2.2 后端为我的 Angular SPA禁用缓存。
我根据这个答案通过OnPrepareResponse为我的StaticFileOptions.
但是Cache-Control标头永远不会被发送。当我在 OnPrepareResponse 操作中设置断点时,我会为每个文件中断,除了 index.html
我在这里缺少什么?我怎样才能真正控制index.html文件的缓存?
// I've changed nothing else in the default ASP.NET Core/Angular template
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// ...
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = context =>
{
// Breakpoint for next line hits for following files
// 1: styles.61d14a95058dbe9da495.css
// 2: runtime.a66f828dca56eeb90e02.js
// 3: polyfills.7a0e6866a34e280f49e7.js
// 4: main.d9791b5a6df420d81994.js
// 5: …Run Code Online (Sandbox Code Playgroud) 假设我必须在我的角度应用程序 xliff 中进行翻译,@@field-is-required它有一个字符串插值,并且@@lastname是正常翻译。
<trans-unit id="field-is-required" datatype="html">
<source><x id="INTERPOLATION" equiv-text="{{ fieldName }}"/> is required</source>
<target><x id="INTERPOLATION" equiv-text="{{ fieldName }}"/> ist Pflichtfeld</target>
</trans-unit>
<trans-unit id="lastname" datatype="html">
<source>Lastname</source>
<target>Nachname</target>
</trans-unit>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以与模板中@@field-is-required的值结合起来吗?@@lastname
我正在想象这样的事情:
<div i18n="@@field-is-required">
{{ '@@lastname' }} is required
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试了几种组合,但对我来说没有任何效果。而且 Angular i18n 的在线文档非常缺乏($localize甚至没有深入解释)。
在我的应用程序中,我有多个选项卡,使用Entity Framework 5显示数据库中的数据.
当我在选项卡之间切换时,我开始通过任务自动加载数据,因为我不希望GUI变得无响应(此任务大约需要5-10秒):
public async void LoadData()
{
[...]
await Task.Run(
() =>
{
Measurements = DataContext.Measurements
.Where(m => m.MeasureDate = DateTime.Today)
.ToList();
});
[...]
}
Run Code Online (Sandbox Code Playgroud)
但是当任务运行时,用户仍然可以更改为另一个选项卡,如果他这样做,我想取消EF查询和/或任务.
实现这一目标的最佳方法是什么?
我有一个带有一些项目的控制器,ng-repeat每个项目应该得到一个随机颜色,所以我使用ng-style该控制器中的一个函数调用randColor(...).
app.controller('TestController', function() {
var vm = this;
vm.items = [ { name: 'item 1' } , { name: 'item 2'} ];
vm.randColor = function (item) {
if (!item) {
return 'red';
}
else if (!item.color)
{
var color = 'rgb('
+ _.random(0, 255) + ','
+ _.random(0, 255) + ','
+ _.random(0, 255) + ')';
item.color = color;
}
return item.color;
};
});
Run Code Online (Sandbox Code Playgroud)
我正在使用"控制器为"语法,我通常总是使用vm我的控制器的短名称.即使以同样的方式命名"子"控制器,我也从来没有遇到过这样的问题.
但是现在我已经尝试用指令做同样的事情,突然我的randColor(...)功能停止了工作.
javascript angularjs angularjs-directive angularjs-controller
在过去,您可以使用isBrowserAngular Universal来检查您的页面是否在浏览器中呈现(因此您可以使用localStorage之类的东西),或者它是否正在进行服务器端预呈现.
但它似乎angular2-universal被解散了@angular/core,@angular/platform-server并且@angular/platform-browser.
我在Angular 4的API文档中寻找类似的功能,并试图在源代码的某个地方找到它,但没有运气.
我错过了什么或Angular 4检查渲染是否在浏览器中运行的方式是什么?或者我应该只检查是否window已定义?
我ResourceDictionary对所有图标都使用 a ,如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas x:Key="Icon.Refresh"
Width="32" Height="32"
Clip="F1 M 0,0L 32,0L 32,32L 0,32L 0,0">
<Path Width="28" Height="28"
Canvas.Left="2" Canvas.Top="2"
Stretch="Fill"
Data="..." />
</Canvas>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
和实际的 XAML:
<Button Content="{StaticResource Icon.Refresh}"
Height="40"
Width="40" />
Run Code Online (Sandbox Code Playgroud)
这工作正常,因为我的大多数按钮都是这个尺寸。但是当我想在较小的按钮上使用它时,它会溢出按钮:
<Button Content="{StaticResource Icon.Refresh}"
Height="30"
Width="30" />
Run Code Online (Sandbox Code Playgroud)

有没有办法设置 a 的大小StaticResource或任何其他聪明的事情可以做?
我目前正试图让自己进入ASP.Net 5开发,而我正在努力找到使用Bower的"方法" .
我的项目结构看起来或多或少像这样:
testProject
- wwwroot
- index.html
- bower_components (hidden by default in project.json)
- angular
- ...
- ...
- node_components (hidden by default in project.json)
- grunt
- ...
- ...
- bower.json
- Gruntfile.js
- package.json
- project.json
- Startup.cs
Run Code Online (Sandbox Code Playgroud)
我无法访问bower_components,index.html因为默认情况下它不包含在项目中我猜它是这样的意思.
那么与凉亭图书馆合作的预期方式是什么?
我已经看到很多人grunt-bower-task用来再次安装库wwwroot/lib(或wwwroot中的其他文件夹),但这对我来说似乎有点多余,因为Visual Studio已经将软件包安装到项目目录中.
另一种方法是使用use grunt-copy将文件移动bower_components到目标文件夹中,但是通过这种方式,您必须再次列出要包含的每个库.
那么有没有人已经获得了一些处理经验,并会分享你是如何做到这一点的?
asp.net visual-studio bower asp.net-mvc-5 visual-studio-2015
c# ×6
.net ×4
angular ×4
javascript ×4
wpf ×4
typescript ×3
angularjs ×2
xaml ×2
accord.net ×1
angular-i18n ×1
asp.net ×1
asp.net-core ×1
bower ×1
canvas ×1
enums ×1
excel ×1
listbox ×1
node.js ×1
textbox ×1