我正在使用WPF在C#中开展项目。我有一个ListView
,它通过绑定到一个对象填充,_name是一个字段。我希望能够通过知道我想要更新哪个_name来更新特定的ProgressBar
。因此,如果当前_name是"任务A",我想更新与#34;任务A"相同的行中的ProgressBar
。但是,由于我无法命名进度条(我在尝试将数据绑定到名称时收到错误消息),因此我无法弄清楚如何访问ProgressBar
代码。我尝试过使用标签,但我还没有弄清楚如何使用某个标签访问控件。任何帮助将不胜感激。下面显示的是我项目中的一些XAML。
<ListView.View>
<GridView>
<GridViewColumn Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding _name}" IsChecked="True"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="200" DisplayMemberBinding="{Binding _name}">Task Name</GridViewColumn>
<GridViewColumn Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ProgressBar Width="145" Height="15" Maximum="100" Value="{Binding _progress}" Tag="{Binding _name}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
答案 0 :(得分:0)
您无法访问public void Copy(String tableName, DataTable dataTable)
{
var insert = $"insert into {tableName} ({GetColumnNames(dataTable)}) values ({GetParamPlaceholders(dataTable)})";
using (var connection = /*a method to get a new open connection*/)
{
for (var row = 0; row < dataTable.Rows.Count; row++)
{
InsertRow(dataTable, insert, connection, row);
}
}
}
private static void InsertRow(DataTable dataTable, String insert, OracleConnection connection, Int32 row)
{
using (var command = new OracleCommand(insert, connection))
{
AssembleParameters(dataTable, command, row);
command.ExecuteNonQuery();
}
}
private static void AssembleParameters(DataTable dataTable, OracleCommand command, Int32 row)
{
for (var col = 0; col < dataTable.Columns.Count; col++)
{
command.Parameters.Add(ParameterFor(dataTable, row, col));
}
}
private static OracleParameter ParameterFor(DataTable dataTable, Int32 row, Int32 col)
{
return new OracleParameter(GetParamName(dataTable.Columns[col]), dataTable.Rows[row].ItemArray.GetValue(col));
}
private static String GetColumnNames(DataTable data) => (from DataColumn column in data.Columns select column.ColumnName).StringJoin(", ");
private static String GetParamPlaceholders(DataTable data) => (from DataColumn column in data.Columns select GetParamName(column)).StringJoin(", ");
private static String GetParamName(DataColumn column) => $":{column.ColumnName}_param";
元素。而是将其ignore
属性绑定到您更新的源对象的属性。
ProgessBar
和Value
(您应该重命名这些)应该是您的数据类型的公共属性,即_progress
的{ {1}}您用作_name
的{{1}}。
这个类应该实现INotifyPropertyChanged :
T
IEnumerable<T>
然后,您只需更改ItemsSource
的{{1}}集合中特定项目的ListView
属性,例如:
public class DataObject : INotifyPropertyChanged
{
private double _progress;
public double Progress
{
get { return _progress; }
set { _progress = value; NotifyPropertyChanged("Progress"); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}