我有一个非常简单的WPF应用程序,它显示一个ComboBox,它绑定到代表人的类列表.每个'Person'对象都有一个Name字符串字段和一个Sex enum.我希望ComboBox显示各种人物名称字段的下拉列表,但是根据性别字段对每一行进行样式设置,例如,蓝色表示男性,粉红色表示女性.谁能告诉我我做错了什么?
这是XML:
<Window x:Class="ComboBoxColour.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">
<StackPanel Orientation="Vertical">
<ComboBox ItemsSource="{Binding People}" Width="100" Height="20">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Name="somePerson" Text="{Binding Path=Name}">
<TextBlock.Triggers>
<DataTrigger Binding="{Binding Path=Sex}" Value="Male">
<DataTrigger.Setters>
<Setter Property="Foreground" Value="Blue" TargetName="somePerson" />
</DataTrigger.Setters>
</DataTrigger>
</TextBlock.Triggers>
</TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
这是C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
namespace ComboBoxColour
{
/// <summary>
/// Interaction logic …Run Code Online (Sandbox Code Playgroud) 我目前正以10秒的间隔使用System.Threading.Timer.每次计时器触发时,我都会添加一小段代码写入文件,而且大多数情况下它会按时触发,有时候(大概是应用程序的其余部分是买的),无法触发30秒或40秒,并连续快速地反复射击.
我可以在.NET 3.5中使用更可靠的计时器吗?
计时器设置如下
Timer someTimer = new Timer(new TimerCallback(SomeMethod), null, 0, 10000);
Run Code Online (Sandbox Code Playgroud)
...回调是:
private static void SomeMethod(object state)
Run Code Online (Sandbox Code Playgroud)
但是,提供比这更多的代码是很困难的,因为Timer通常会正确触发.当它嵌入一个大型应用程序(约100,000行左右)时,多个线程被射击,左,右和中心,你慢慢开始看到计时器间歇性地发射.我看过几篇帖子暗示ThreadPool可能已经用尽了,所以我现在正在寻找这个可能是我正在经历的内容.
我有一个创建预定事件的 SQL 脚本:
CREATE EVENT "Daily_1200PM"
SCHEDULE "Daily_1200PM" START TIME '12:00' EVERY 24 HOURS
HANDLER
begin
-- Blah blah, do some stuff here
end;
Run Code Online (Sandbox Code Playgroud)
我想删除此事件(如果存在)。我知道我可以通过以下方式删除事件:
DROP EVENT "Daily_1200PM"
Run Code Online (Sandbox Code Playgroud)
但是对于某些数据库,该事件实际上并不存在,因此会引发错误。
如何仅在事件存在时删除该事件?
c# ×2
.net ×1
combobox ×1
datatemplate ×1
schedule ×1
sql ×1
sqlanywhere ×1
styling ×1
timer ×1
wpf ×1