我有这个 Payment 对象
public class Payment
{
public Guid Id { get; set; }
public double Amount { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是绑定到 TextBox 的数据
<TextBox x:Name="_AmountTB" Text="{Binding Path=Amount, Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)
我要求每当金额为 0 时,我就不会在文本框中显示任何内容,该怎么办?
我正在考虑某种转换器,但我需要有人告诉我如何做到这一点?!
谢谢,
巫毒教
为什么var excludes = users.Except(matches);不排除matches?
如果我希望相等比较器只使用ID?,那么正确的方法是什么?例子将不胜感激.
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public override string ToString()
{
return ID.ToString() + ":" + Name;
}
}
private static void LinqTest2()
{
IEnumerable<User> users = new List<User>
{
new User {ID = 1, Name = "Jack"},
new User {ID = 2, Name = "Tom"},
new User {ID = 3, Name = "Jim"},
new User {ID …Run Code Online (Sandbox Code Playgroud) 我以编程方式设置wcf客户端参数,如下所示:
try
{
ServiceReference1.MyDbServiceClient webService =
new ServiceReference1.MyDbServiceClient(new System.ServiceModel.BasicHttpBinding(),
new System.ServiceModel.EndpointAddress((string)((App)Application.Current).Resources["wcfMyDBServiceEndPoint"]));
webService.GetSeriesImagesCompleted += new EventHandler<ServiceReference1.GetSeriesImagesCompletedEventArgs>(webService_GetSeriesImagesCompleted);
webService.GetSeriesImagesAsync(index);
}
Run Code Online (Sandbox Code Playgroud)
它适用于默认的maxBufferSize.但是,当客户端超过默认大小时,会出现例外情况:"已超出传入邮件的最大邮件大小限额(65536)."
如何在代码中设置此参数?谢谢.
好吧,这看起来很难看:)重构这段代码的好方法是什么?
Users 是在屏幕上输入的数据,对于这个例子,我们希望得到不同的结果 _someDTOObject.Users
string[] userNames = Users.Split(new char[] { ',' });
string tempUserStr = "";
foreach (string user in userNames)
{
tempUserStr += user.Trim().ToUpper() + ",";
}
userNames = tempUserStr.Split(new char[] { ',' });
var uniqueUsers = userNames.Distinct().ToList();
foreach (string user in uniqueUsers)
{
if (!string.IsNullOrEmpty(user))
{
_someDTOObject.Users += user + ",";
}
}
Run Code Online (Sandbox Code Playgroud) 我的Google Analytics似乎无效,因为我已阻止所有用户代理.我的网站仍然处于测试版,所以我不想让搜索引擎看到,但我仍然希望观看我的网站分析数据.
如何在robots.txt中允许Google Analytics?
在IIS中托管的ASP.NET应用程序的压力/负载测试期间,我应该在应用服务器上监控什么?
例如,Windows中内置的实用程序性能监视器有一个巨大的计数器列表,我可以监视.但是,我甚至不知道这些计数器中有一半实际上是什么意思?我知道我想看看内存,处理器,网络......但它很通用.
我怎样才能成功找到问题区域?
你们中的一些人过去使用了什么?
popUpControl和listBoxControl下面正在返回NaN作为高度和宽度.这ActualHeight也是0.0
为什么?更重要的是,解决方法是什么?
<Popup Name="popUpControl" IsOpen="True" VerticalAlignment="Top" HorizontalAlignment="Left" >
<ListBox Name="listBoxControl" SelectionChanged="_ListBox_SelectionChanged"
Style="{StaticResource ListBoxStyle}" BorderBrush="Transparent"
MaxHeight="300" MaxWidth="350" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding ID}" VerticalAlignment="Center" Margin="2,0,0,0" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="2,0,0,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
Run Code Online (Sandbox Code Playgroud) 我是LINQ的新手.我正在看这段代码,不确定我是否理解这一点.我意识到它是一个扩展和泛型方法,但正在predicate(item, index)执行什么(假设我在调用此方法时传入一个int数组)?
我知道谓词是一个委托,但也许我只是不知道委托如何运作,有人有任何他们想要给出的好的例子/解释.另外,什么是yield关键字,它只是用于linq的东西?
private static IEnumerable<TSource> WhereImpl<TSource>(
this IEnumerable<TSource> source,
Func<TSource, int, bool> predicate)
{
int index = 0;
foreach (TSource item in source)
{
if (predicate(item, index))
{
yield return item;
}
index++;
}
}
Run Code Online (Sandbox Code Playgroud)
我试图跟随Reimplementing LINQ to Objects:第2部分 -来自Skeet博客的"Where".
在我的课程中,我注意到下面的模式.我怎么能把它抽象出来呢?有什么建议?
private void InitializeClass()
{
BackgroundWorker bgw1 = new BackgroundWorker();
bgw1.DoWork += (s,e) =>
{
// doing work
};
BackgroundWorker bgw2 = new BackgroundWorker();
bgw2.DoWork += (s,e) =>
{
// doing work
};
BackgroundWorker bgw3 = new BackgroundWorker();
bgw3.DoWork += (s,e) =>
{
// doing work
};
bgw1.RunWorkerAsync();
bgw2.RunWorkerAsync();
bgw3.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud) boolean根据int计数器属性设置属性的最佳方法是什么?
所以,假设我有10个布尔属性
public bool IsBool1 {get;set;}
....
public bool IsBool10 {get;set;}
Run Code Online (Sandbox Code Playgroud)
和一个int计数器(永远不会有大于10的值)
public int Counter {get;set;}
Run Code Online (Sandbox Code Playgroud)
最后,我有一个设置标志的方法
private void SetFlagsByCounter(int counter)
{
if (counter >= 1) { IsBool1 = true; }
.....
if (counter >= 10) { IsBool10 = true; }
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来设置标志而不是迭代计数器?
我目前停留在通过转换器为控件分配不同模板的问题上.
所以我有2个模板.
<ControlTemplate x:Name="_templateA" x:Key="templateA">
<StackPanel Grid.Column="0" Margin="0,0,5,0">
<Blah />
</StackPanel>
</ControlTemplate>
<ControlTemplate x:Name="_templateB" x:Key="templateB">
<StackPanel Grid.Column="0" Margin="0,0,5,0">
<Blah Blah />
</StackPanel>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
我使用这个转换器控制这个:
<ControlA x:Name="_controlA" >
<Control Template="{Binding Converter={StaticResource templateConverters}}" />
</ControlA>
Run Code Online (Sandbox Code Playgroud)
我的转换器:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Object a;
ControlTemplate template = null;
try
{
a= value as ObjectA;
if (value != null)
template = a.useTemplate1 ? [templateA from xaml] : [templateB from xaml];
}
catch (Exception ex)
{
Debug.Assert(false, ex.ToString());
} …Run Code Online (Sandbox Code Playgroud) Execute批量调用该方法的一个好方法是rulesObjs什么?可以说该列表包含超过10,000个对象,而我想一次调用的对象Execute不超过500个。
public static List<object> ExecutePolicy()
{
Policy policy = new Policy();
List<object> rules = GetRules();
object[] rulesObjs = rules.ToArray();
// Call this method with array of object, but in batches.
policy.Execute(rulesObjs);
return rulesObjs.ToList();
}
private static List<object> GetRules()
{
// get the rules via some process
return new List<object>();
}
}
public sealed class Policy
{
public void Execute(params object[] rules)
{
// Process rules...
}
}
Run Code Online (Sandbox Code Playgroud)
我无法控制Execute()方法。
c# ×7
linq ×2
silverlight ×2
wpf ×2
actualheight ×1
actualwidth ×1
arrays ×1
binding ×1
converter ×1
data-binding ×1
datatemplate ×1
load-testing ×1
perfmon ×1
refactoring ×1
robots.txt ×1
string ×1
wcf-binding ×1
web-crawler ×1
xaml ×1