元素编号更改时绑定到列表元素
Binding to List element when element number changes
private List<Report> _reports = new List<Report>();
public Report CurrentReport
{
get { return _reports[_componentIterator]; }
set { _reports[_componentIterator] = value; }
}
我有一个 _reports 字段,它是一个报表对象列表。
我使用 CurrentReport 属性 访问基于 _componentIterator 的当前 Report 对象。
如何绑定到某些报表属性,以便更改 _componentIterator 不会破坏我的绑定?
如果我这样绑定,每个 _componentIterator 更改都会破坏绑定。
Binding designatorTextBlockBinding = new Binding(nameof(CurrentReport.Designator));
designatorTextBlockBinding.Source = CurrentReport;
_artifactControl.DesignatorTextBlock.SetBinding(Controls.TextBlock.TextProperty, designatorTextBlockBinding);
如下所示声明绑定,并确保 CurrentReport
属性 触发更改通知。
var designatorTextBlockBinding = new Binding
{
Path = new PropertyPath("CurrentReport.Designator"),
Source = this
};
或
var designatorTextBlockBinding = new Binding
{
Path = new PropertyPath(
nameof(CurrentReport) + "." + nameof(CurrentReport.Designator)),
Source = this
};
或
var designatorTextBlockBinding = new Binding(
nameof(CurrentReport) + "." + nameof(CurrentReport.Designator))
{
Source = this
};
private List<Report> _reports = new List<Report>();
public Report CurrentReport
{
get { return _reports[_componentIterator]; }
set { _reports[_componentIterator] = value; }
}
我有一个 _reports 字段,它是一个报表对象列表。
我使用 CurrentReport 属性 访问基于 _componentIterator 的当前 Report 对象。
如何绑定到某些报表属性,以便更改 _componentIterator 不会破坏我的绑定?
如果我这样绑定,每个 _componentIterator 更改都会破坏绑定。
Binding designatorTextBlockBinding = new Binding(nameof(CurrentReport.Designator));
designatorTextBlockBinding.Source = CurrentReport;
_artifactControl.DesignatorTextBlock.SetBinding(Controls.TextBlock.TextProperty, designatorTextBlockBinding);
如下所示声明绑定,并确保 CurrentReport
属性 触发更改通知。
var designatorTextBlockBinding = new Binding
{
Path = new PropertyPath("CurrentReport.Designator"),
Source = this
};
或
var designatorTextBlockBinding = new Binding
{
Path = new PropertyPath(
nameof(CurrentReport) + "." + nameof(CurrentReport.Designator)),
Source = this
};
或
var designatorTextBlockBinding = new Binding(
nameof(CurrentReport) + "." + nameof(CurrentReport.Designator))
{
Source = this
};