我有一个ListBoxItem的数据模板,它包含几个按钮,以及很少的自定义控件,如网格或图表.每个按钮都绑定到一个合适的命令处理程序,ListView控件的SelectedIndex属性也绑定到ViewModel的属性.
问题:在命令处理程序(绑定到按钮)中我无法解析当前选定的项目/索引,因为它在单击ListBox项目中的按钮或其他控件时没有改变,但是当我单击ListBoxItem区域本身时 - SelectedIndex正在改变.
问题是如何在单击ListBoxItem中的任何控件时触发SelectedIndex被更改?
我有以下linq:
objfl = db.tblFl.First(t => t.sp == id && t.ProgID == sPgm);
Run Code Online (Sandbox Code Playgroud)
我也想通过id订购,但不知道如何做到这一点.我尝试了许多不同的方法,但没有成功
Microsoft在哪些方面利用了适配器模式?我正在寻找使用适配器的.NET组件的具体示例.
我正在尝试模拟ToString()我的自定义对象的调用.我已经为界面创建了一个模拟,并在ToString()通话时设置了期望值
interface ICustomObject
{
}
var customObjectMock = MockRepository.GenerateMock<ICustomObject>();
var fakeDump = Guid.NewGuid().ToString();
customObjectMock.Expect(c => c.ToString()).Return(fakeDump).Repeat.Any();
Run Code Online (Sandbox Code Playgroud)
在测试运行时,我得到了运行时异常说:
System.InvalidOperationException:无效的呼叫,已使用的最后一个呼叫或未进行任何呼叫(确保您正在呼叫虚拟(C#).
众所周知的错误,但为什么我认为它ToString()是虚拟的呢?
而且更有趣 - 我只是通过ToString()在界面中明确定义来解决它:
interface ICustomObject
{
// Weird! I believe such method definition in interface would be confusing
// without a special remark comment saying that this method is redefined
// to satisfy RhinoMocks (perhaps Reflection?)
string ToString();
}
Run Code Online (Sandbox Code Playgroud)
在此之后,RM允许设定期望值ToString().
只是想知道为什么RinoMocks要求我重新定义标准虚拟化Object.ToString()?也许RM不考虑可用于每个框架对象的这种标准方法,并且有义务重新定义所有方法/属性;为了能够设定期望,我们必须这样做?
我在表中有一个名为CreatedOn的Datetime列.CreatedOn也是订单下降的非聚集索引的一部分.
以前在哪里条件我有如下条件
WHERE DateDiff(d,CreatedOn,GetDate()) < 180 AND ... other conditions
Run Code Online (Sandbox Code Playgroud)
我把它改成了
WHERE CreatedOn > '2012-04-04 00:00:00.000' AND ... other conditions
Run Code Online (Sandbox Code Playgroud)
我在C#代码中计算截止日期,然后将其放入adhoc查询中.
据我说,第二个条件应该更快,但我还没有看到查询执行时间的重大变化.但随着桌子大小的增加,哪一个会跑得更快?
我想我失去了一些东西有关的正确行为Monitor.Enter和Monitor.TryEnter.这是我编写的一段代码,用于将问题与其余代码分开:
object lockObj = new object();
bool result = Monitor.TryEnter(lockObj);
Console.Write(result);
Run Code Online (Sandbox Code Playgroud)
结果总是如此true.这里没有惊喜.
object lockObj = new object();
Monitor.Enter(lockObj);
bool result = Monitor.TryEnter(lockObj);
Console.Write(result);
Run Code Online (Sandbox Code Playgroud)
但这次也是true.所以是否lockObj被锁定Monitor.Enter?请给我一些新的看法.
我在下面的行中收到错误.
temp.day1_veh_p = string.Join(Environment.NewLine, day1.Where(x => x.plannedTriips == 1).Select(x => new {value=x.vehicleNumber+":"+x.shiftCompletedOn }).Cast<string>().ToArray());
Run Code Online (Sandbox Code Playgroud)
错误消息正在发送
Unable to cast object of type '<>f__AnonymousType0`1[System.String]' to type 'System.String'.
Run Code Online (Sandbox Code Playgroud)
列表day1是类型
public class tripDetails
{
public string accountID { get; set; }
public string supplierName { get; set; }
public string supplierCode { get; set; }
public DateTime shiftFrom { get; set; }
public DateTime shiftTo { get; set; }
public int plannedTriips { get; set; }
public int actualTrips { get; set; }
public DateTime …Run Code Online (Sandbox Code Playgroud) public class Currency{
private Code {get;set;}
public Currency(string code){
this.Code = code;
}
//more methods here
}
Run Code Online (Sandbox Code Playgroud)
我希望能够使我的对象成为可投射的
string curr = "USD";
Currency myType = (Currency)curr;
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用构造函数来完成它,但是我在不需要初始化对象的情况下使用了我需要的地方...
我也相信生病需要像FromString()这样做的功能
谢谢.
这是方法:
public IEnumerable<???> GetAllSiteVisits()
{
var visits =
_db.STEWARDSHIP
.OrderByDescending(r => r.VISIT_DATE)
.Select(r => new
{
id = r.STEWARDSHIP_ID,
name = r.SITE.SITE_NAME,
visit_date = r.VISIT_DATE,
visit_type = r.VISIT_TYPE_VAL.VISIT_TYPE_DESC
});
return visits;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Entity Framework 4.2.
所以问题在于找出返回类型.如果我只是直接从数据库表中使用信息,我会返回,IEnumerable<STEWARDSHIP>但由于我只选择某些字段,我不明白返回类型是什么.
存在这样的情况:应用系统需要每1分钟向在线用户发布消息,并且代码使用多头任务来读取消息列表.但程序运行不正常,会抛出一个超出范围异常的索引.请有人可以提出任何建议,谢谢.
private Timer taskTimer;
private static readonly object _locker = new object();
private static IList<Message> _messages = null;
private void OnTimerElapsed(object sender)
{
var msgModel = new MessageModel();
_messages = msgModel.GetMessageList();
var msgCount = _messages.Count();
Task[] _tasks = new Task[msgCount];
for (int i = 0; i < msgCount; i++)
{
if (i < msgCount)
{
_tasks[i] = Task.Factory.StartNew(() =>
{
lock (_locker)
{
PushMessage(i);
}
});
}
}
//waiting all task finished
while (_tasks.Any(t => !t.IsCompleted)) { }
}
private …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×7
linq ×2
adapter ×1
casting ×1
custom-type ×1
list ×1
listview ×1
mocking ×1
rhino-mocks ×1
sql ×1
sql-order-by ×1
sql-server ×1
t-sql ×1
task ×1
wpf ×1