我需要从运行时分配给var的某个LINQ接收一个类型,显然,我可以自己将var转换为我的类型,但我相信LINQ是错误的,(可能缺少Select?)任何人都可以指出我在正确的方向?谢谢
-----代码------
// there is only one active flag which is true in the collection...
var selected = m_PersonCollection.Where(t => t.Active == true)
// Thinking this is the way it is done...
Person person = selected as Person;
Run Code Online (Sandbox Code Playgroud) 我已经四处寻找解决问题的方法,但我相信很多可用的解决方案都是为了解决这个问题.
基本上我在Datagrid单元格中有一个正在运行的进度条.但是,我现在想在进度条中放置文本以显示实际百分比.这是怎么做到的?
到目前为止我的代码
<DataGridTemplateColumn Header="Percentage Downloaded" Width="5*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ProgressBar Value="{Binding Path=PercentageDownloaded, Mode=OneWay}" Minimum="0" Maximum="100" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)
为了代表我付出努力,我尝试在进度条中使用tag属性并使用两个都失败的文本块.
非常感谢
*解决方案*
GiangregorioC提供的解决方案有效,因为我没有意识到你可以将标签放在DataGridCellTemplate中!
当鼠标离开一行时,我有一个鼠标离开事件
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseLeave" Handler="Row_MouseLeave"></EventSetter>
</Style>
</DataGrid.RowStyle>
Run Code Online (Sandbox Code Playgroud)
所以在处理程序中,我尝试获取与行有界的下划线项目
private void Row_MouseLeave(object sender, MouseEventArgs args)
{
DataGridRow dgr = sender as DataGridRow;
<T> = dgr.Item as <T>;
}
Run Code Online (Sandbox Code Playgroud)
但是,项目是占位符对象,而不是项目本身。
通常,您可以通过 DataGrid selectedIndex 属性执行我想要的操作。
DataGridRow dgr = (DataGridRow)(dg.ItemContainerGenerator.ContainerFromIndex(dg.SelectedIndex));
<T> = dgr.Item as <T>
Run Code Online (Sandbox Code Playgroud)
但作为 ItemSource绑定到 DataGrid,而不是 DataGridRow,DataGridRow 无法看到绑定到网格的集合......(我假设)
但由于我没有选择一行,我真的不能这样做。那么有什么方法可以做我想做的事吗?
干杯
我有这个Linq语句,如果property不是NULL,它会成功构建一个列表
results.AddRange(m_CTS.Entity.Where(x => x.Property.Contains(search)).ToList());
Run Code Online (Sandbox Code Playgroud)
但是,如果x.property为null然后它出错,那么我想尝试将其检查为null,如果它不为null,则继续构建列表.
我试过了,
results.AddRange(m_CTS.Entity.Where(x => x.Property == null ? "" : x.Property.Contains(search)).ToList());
Run Code Online (Sandbox Code Playgroud)
但这也是错误,我做错了什么?
提前致谢
我无法创建一个类或我自己的对象,所以我想我会使用a List<KeyValuePair>来存储两个属性,然后将这个对象绑定到一个组合框.
但是,我无法看到如何在组合框中设置valueField和TextField.
代码.
List<KeyValuePair<int, string>> kvpObject =
new List<KeyValuePair<int, string>>();
foreach (User u in m_users) {
kvpObject.Add(new KeyValuePair<int, string>(u.ID, u.Name));
}
// Bind Add Users combobox
cmboBox.DataSource = kvpObject;
cmboBox.ValueField = "????" // Maybe something like kvpObject[0]..
cmboBox.TextField = "????";
cmboBox.DataBind();
Run Code Online (Sandbox Code Playgroud)
有谁知道我需要把它放进去????.
我正在将 10MB 文件 (blob) 写入数据库,每次迭代使用 64KB。然而,这比从数据库中读取同一个文件花费的时间几乎是两倍,读取数据库比写入数据库快这是正常的吗?
谢谢
希望应该是一个简单的.我创建了一个通用错误视图,我希望在整个站点的操作方法内发生异常时显示该视图.我创建了一个部分页面,其中所有导航都存在,因此我不需要在此视图上使用控制器,因此如何从控制器内的操作方法重定向到它?
像这样......
[HttpPost]
public ActionResult Test(VM viewModel)
{
try
{
// posting info to the server...
}
catch (Exception ex)
{
//Log exception..
//show an error view, however no action method so how do I redirect?
return RedirectTo ??? ("Error");
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我想知道是否有一种方法能够在不使用错误回调的情况下捕获可观察对象的订阅错误?
例如,您捕获这样的错误
.subscribe({
next: (obj) => {
// Placeholder for code
},
// At the moment we need to include this error callback to show that an error has happened.
// Forgetting to put this in means it 'bubbles' up so we cannot catch it and do anything with it.
error: (e) => {
this.showError(e.message);
},
Run Code Online (Sandbox Code Playgroud)
但如果你看一下上面的评论,就会发现这就是不包含回调时会发生的情况。
忘记把它放进去意味着它会“冒泡”,所以我们无法抓住它并用它做任何事情。
更明确地说,即使在try-catch该方法周围放置一个也不会捕获错误。
我想知道这一点,因为如果由于某种原因,开发人员忘记放入 catch 回调,有什么方法可以捕获它吗?因为如果不是,则无法处理错误。
我认为问题在于,可观察的是一个异步进程,它发生在新的线程/任务上。
谢谢
我想知道是否有可能将组合框内的selectedItem与枚举值进行比较。例如
if (cmb.SelectedItem == Enum.Value) ...
Run Code Online (Sandbox Code Playgroud)
目前我正在通过ToString()
if (cmb.SelectedItem.ToString() == "Value")
Run Code Online (Sandbox Code Playgroud)
谢谢
我有这个LINQ可以完成我想要的工作
var query = context.MasterTemplateOfficeTag
.Join(context.Tag, x => x.TagId, y => y.Id, (x, y) => new { y.Name })
.ToList();
Run Code Online (Sandbox Code Playgroud)
虽然我的问题是我希望LINQ返回一个,list<String>因为Select语法=> new { y.Name })是类型的string.因此如果编译器知道返回类型,为什么我不能使用list<String>?
我想要这样的东西
List<String> name = context.MasterTemplateOfficeTag
.Join(context.Tag, x => x.TagId, y => y.Id, (x, y) => new { y.Name })
.ToList();
Run Code Online (Sandbox Code Playgroud)
这可能吗?
谢谢
c# ×8
linq ×3
datagrid ×2
wpf ×2
.net ×1
angular ×1
asp.net-mvc ×1
combobox ×1
enums ×1
keyvaluepair ×1
progress-bar ×1
rxjs ×1
sql-server ×1
winforms ×1