小编use*_*387的帖子

如何在Observable Collection中搜索项目并获取其索引

 public struct PLU { 
         public int ID { get; set; } 
         public string name { get; set; } 
         public double price { get; set; } 
         public int quantity {get;set;}

 }
 public static ObservableCollection<PLU> PLUList = new ObservableCollection<PLU>();
Run Code Online (Sandbox Code Playgroud)

我有如上所述的ObservableCollection.现在我想在PLUList中搜索ID 并得到它的索引:

int index = PLUList.indexOf();
if (index > -1) {
// Do something here
}
else {
// Do sth else here..
}
Run Code Online (Sandbox Code Playgroud)

什么是快速解决方案?

编辑:

我们假设有些项目被添加到PLUList,我想添加另一个新项目.但在添加之前,我想检查列表中是否已存在ID.如果确实如此,我想在数量上加+1.

.net c# struct observablecollection

5
推荐指数
1
解决办法
5万
查看次数

如何使用WPF窗口作为消息框?

我创建了一个带有一些风格的小窗口.现在我想像MessageBox一样使用它.我怎样才能实现它?

编辑:我是WPF的新手.我试着像这样在主窗口中调用它.

Window1 messageBox = new Window1();
messageBox.Show();
messageBox.Activate();
Run Code Online (Sandbox Code Playgroud)

问题是新生成的窗口在主窗口后面消失,而不让我点击其中的操作按钮.

.net c# wpf

4
推荐指数
1
解决办法
1445
查看次数

Itemscontrol中的Itemscontrol并使用自定义数据绑定它们

我是WPF的新手.我一直在努力做到以下几点:

以下是我的数据结构:

public class TokenItems {public string items {get;set;} public int quantity {get;set}}
public class Token { public int tokenNo {get;set;} public string name {get;set;} public   List<TokenItems> currentItems {get;set;}}
public List<Token> tokenList = new List<Token>();
Run Code Online (Sandbox Code Playgroud)

XAML:

<ItemsControl Name="ParentControl">
   ....
   <DataTemplate>
   <TextBlock Content="{Binding tokenNo}"/>

   <Itemscontrol Name="{Binding tokenNo}">  ?? I tried and want dynamic naming or any other solution for this {Binding name} just won't work i know.??
      ...
      <DataTemplate>
        <Button>
            <Grid>
               ...
               <TextBlock Content="{Binding items}/>
               <TextBlock Content="{Binding quantity}/>
      </DataTemplate>

   </Itemscontrol>
     .... …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf

4
推荐指数
1
解决办法
3145
查看次数

WPF中线程的一个非常基本的解释?

我对WPF非常新.我在互联网上查看了几个关于线程的示例和教程.他们有自己的描述方式.但对于像我这样天真的人,我想用自己的风格来理解.

我可以使用数据库更新功能开始我的第一次线程.

这是场景:

我有大量数据要插入数据库中.现在让我们假设以下代码(一旦我点击"继续"按钮,这个过程就会启动:

int initial = 0;
int maxData = 10
while (initial<maxData) {
   //Database query here
}
Run Code Online (Sandbox Code Playgroud)

上面的过程将在不同的线程中运行.

接下来我在主窗口中有一个"标签".对于每个数据库查询,我想在标签中显示一些消息.

例如,

// this will happen in default UI thread.
label.Content = "Updating"; // Specifically for @TomTom ;)
Run Code Online (Sandbox Code Playgroud)

编辑:我做了以下事情:

var task = new Task(() =>
    {
       for (int i=0; i<10; i++) {
          //Create new Grid HERE
          // Add Table with some dynamic data here..
          // print the above Grid here.
        }

    });

task.ContinueWith((previousTask) =>
    {
        label.Content = printerStatus(); // will …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf multithreading

2
推荐指数
1
解决办法
1万
查看次数

如何预先设置公共结构中的值?

public struct customerItemListStruct { 
        public int ID { get; set; } 
        public string name { get; set; } 
        public double rate { get; set; } 
        public int quantity { get; set; } 
        //public double total = rate * quantity; 
Run Code Online (Sandbox Code Playgroud)

}

我想预先设定总值.

建议我最好的方法!谢谢!

.net c# struct

1
推荐指数
1
解决办法
108
查看次数

标签 统计

.net ×5

c# ×5

wpf ×3

struct ×2

multithreading ×1

observablecollection ×1