gpt4 book ai didi

wpf - 两个自定义依赖对象之间的绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 20:32:47 25 4
gpt4 key购买 nike

我在 xaml 中创建了一个自定义依赖对象,我想将它的整个实例绑定(bind)到另一个自定义依赖对象的属性。控件内部发生的所有事情。
例如像这样的东西

class row : dependencyobject
{
// this is a dp property
public static readonly dependencyproperty widthproperty = dependencyproperty.register...
}

class cell : dependencyobject
{

public static readonly dependencyproperty dataproperty = dependencyproperty.register....
}

class customGridView:Control
{
List<Row>Rows { get;set;}
List<Cell> Cells { get;set;}
}

现在我想将一个行的实例绑定(bind)到 cell.data 属性,也是这样的:
<customGridView>
<row x:name:row1 width=200/> (this is a class that derives for dependencyobject)
<row .../>
<cell data={Binding ElementName=row1}/> (this is another class that derives from dependencyobj and tries to bind to entire instance of row class)
<cell ..../>
<cell ..../>
</customGridView/>

有什么帮助吗?

根据需要,这是 cell.data 的 dp 属性:
 public Row Data
{
get { return (Row)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}

// Using a DependencyProperty as the backing store for ColumnName. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DataProperty=
DependencyProperty.Register("Data", typeof(Row), typeof(Cell), new PropertyMetadata(null));

最佳答案

现在我得到了你的问题这样做

  <cell.data>
<x:Reference Name="row1"/>
</cell.data>

关于wpf - 两个自定义依赖对象之间的绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13449716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com