让我说我有一个文件,想要阅读这些行,它是:
while( !streamReader.EndOfStream ) {
var line = streamReader.ReadLine( );
}
Run Code Online (Sandbox Code Playgroud)
我如何只读取一系列行?像只有10到20的读数线.
如何创建像RadioButton这样的布尔属性?你知道,就像RadioButton一样,只能选择一个吗?
比如下面的例子.
当我将一个Employee设置IsResponsiblePerson为true时,它应该将所有其他Employee 设置为false.不使用循环.
var list = new ObservableCollection<Employee>();
public class Employee
{
public string Name{get;set;}
public string Surname{get;set;}
public bool IsResponsiblePerson{get;set;}
}
Run Code Online (Sandbox Code Playgroud) 如何订购不同的部署环境。仅用于显示目的。目前,我们的立场是这样的:
我希望它看起来像这样:
开发--测试-验收--生产
azure-devops azure-pipelines azure-pipelines-release-pipeline
我有2个控件:
DatePicker:仅用于日期
文本框与TimeMask:仅用于时间
它们都链接到相同的属性,DateTime EffectiveDate
但是问题是当我更改DatePicker上的Date时,它将TimeTextBox中的Time更改回12:00。
我知道原因,但是有什么最好的解决方案可以让它们分开工作但绑定到同一属性?
我试图采用当前时间并在set属性中建立一个新的Date,但总是以溢出错误告终。
我有一个可以为null的Date属性BoughtDate.我正在尝试以下方法:
if( item.BoughtDate.Value.Equals( DateTime.MaxValue) ) item.BoughtDate= null;
Run Code Online (Sandbox Code Playgroud)
还试过这个:
if( item.BoughtDate.Equals( DateTime.MaxValue) ) item.BoughtDate=null;
Run Code Online (Sandbox Code Playgroud)
调试时,我BoughtDate和DateTime.MaxValue似乎一模一样-但它说,这是不一样的(不设置我item.BoughtDate为null)
为什么我的比较不起作用?
我有时会收到一个错误:
There is not a header with name UserName and namespace http://www.website.com/ in the message.
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
System.ServiceModel.Channels.MessageHeaders.GetHeader [T](String name,String ns,String [] actors)Common.Utilities.WCF.WcfCallContext.TryGetHeader(String key)Common.Utilities.WCF.WcfCallContext.get_UserName()
这是2种方法:
private static string TryGetHeader( string key )
{
try
{
return GetHeader( key );
}
catch
{
return null;
}
}
private static string GetHeader( string key )
{
var headers = OperationContext.Current.IncomingMessageHeaders;
var value = headers.GetHeader<string>( key, "http://www.website.com/", "Project" );
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
所以TryGetHeader(使用try和catch)调用GetHeader.显然它打破了:
var value = headers.GetHeader<string>( key, "http://www.website.com/", "Project" ); …Run Code Online (Sandbox Code Playgroud) 任何人都可以通过Powershell脚本来帮助我。我已经在线搜索了,无法获得准确的答案。我需要一个脚本来递归删除文件夹中所有扩展名为.stat且小于500bytes的文件。然后按回车键将继续删除所有文件
如果我有一个字符串,例如:“this.is.a.string.and.I.need.the.last.part”我试图在最后一个“.”之后获取字符串的最后一部分,在这个案例是“部分”我如何实现这一目标?我尝试的一种方法是将字符串拆分为“.”,我得到一个数组,但是我不知道如何检索数组中的最后一项。
| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".")
Run Code Online (Sandbox Code Playgroud)
给我:
["this", "is","a","string","and","I","need","the","last", "part"]
Run Code Online (Sandbox Code Playgroud)
第二次尝试我试过这个:
| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)
Run Code Online (Sandbox Code Playgroud)
但是 Kusto 没有 lastindexof 的功能。
有人有提示吗?
有人可以帮助我。我已经为 TabItem 标题编写了样式。但是因为我的 TabItem Header 是绑定的,所以我需要使用 TabControl.ItemTemplate 而不是 TabItem Header
那么我如何开始在 TabControl.ItemTemplate 上获得与 TabItem 相同的样式
所以我有这个:
<TabItem Header="Tab1" Style="{StaticResource TabStyle}">
</TabItem>
Run Code Online (Sandbox Code Playgroud)
现在我有这个:
<TabControl.ItemTemplate>
<!-- this is the header template-->
<DataTemplate>
<TextBlock Text="{Binding Person}" />
</DataTemplate>
</TabControl.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
这是原始 TabItem 的样式:
<Style x:Key="TabStyle" TargetType="{x:Type TabItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border Padding="3">
<Grid Name ="grid" Height="24">
<Border Name="BorderName"
CornerRadius="12,12,12,12"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Rectangle Name="TabItemBackgorund"
RadiusX="12"
RadiusY="12"
Fill="{StaticResource TabItemBackgroundBrush}"> …Run Code Online (Sandbox Code Playgroud) 我有一个继承自 ViewModelBase 的 ViewModel。目前我在 ViewModel 中调用我的服务,如下所示:
private void Login(string _username, string _password)
{
Task.Run(async () =>
{
var isLoginSuccess = await _authenticationDataService.Login(_username, _password);
if (isLoginSuccess == true) { }
});
}
Run Code Online (Sandbox Code Playgroud)
在我的 AuthenticarionService 中,它看起来像这样:
public async Task<bool> Login(string username, string password)
{
Token = await GetAPIToken(username, password);
return true;
}
private static async Task<string> GetAPIToken(string userName, string password)
{
//Blah blah blah wont bore you with the detail
}
Run Code Online (Sandbox Code Playgroud)
现在我想要的是在我的 ViewModelBase 中放置一个通用的 Task 方法,它将运行我传递给它的任何“awaitables”并返回一个通用结果(我可以在我的视图模型中正确地转换结果)。
这样我就可以做这样的事情:
private void Login(string _username, string …Run Code Online (Sandbox Code Playgroud) 我有一段代码,我想弄清楚hash(#)字符串内部是什么.
以下是这段代码.
var key = string.Format( "{0}#{1}#{2}", value1, value2, value3);
if ( !instance.Map.ContainsKey( key ) )
{
throw new Exception("Dear Customer, your order cant be identified.");
}
Run Code Online (Sandbox Code Playgroud)
我不认为我曾经使用#过C#
如果我没有提供value3它仍然找到钥匙.因此我认为#意味着强制性或部分性.
c# ×8
mvvm ×2
wpf ×2
azure ×1
azure-devops ×1
azure-pipelines-release-pipeline ×1
data-binding ×1
datepicker ×1
datetime ×1
generics ×1
powershell ×1
streamreader ×1
string ×1
task ×1
viewmodel ×1
xaml ×1