如何覆盖堆栈面板中的数据上下文?
如何覆盖第一个内部堆栈面板的数据上下文...以便..我可以引用 A 类中的属性
Class A
{
public B b;
}
Class B
{
}
<stack panel DataContext = b >
<stack panel>
// HEre I use properties from class A
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
</stack panel>
How to override the first inner stack panel's data context...So that..I can refer the properties in class A
Class A
{
public B b;
}
Class B
{
}
<stack panel DataContext = b >
<stack panel>
// HEre I use properties from class A
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
<stack panel>
// HEre I use properties from class B
</stack panel>
</stack panel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几种方法取决于您的课程的实际设置方式。
创建引用对象父类的关联属性。如果 B 类是 A 类的子类,则 B 类中可以有一个属性引用包含该 B 类的 A 对象。当您的 DataContext 在顶级堆栈面板上设置时,您的第一个子级可以具有类似 DataContext="{Binding Parent}" 的内容,其中父级是引用 ClassA 的属性。
只需将顶级堆栈面板中的 DataContext 设置为 ClassA 绑定,将第一个子项留空,并将其设置为每个连续堆栈面板的 b 属性。
如果我理解您的权利,请告诉我。我可能需要更多有关您的程序和问题的背景信息。
此外,复制/粘贴真实代码比直接键入要好。真实的代码通常会为问题提供更好的上下文。
Couple of ways depending on how your classes are actually set up.
Create an association property that refers to the parent class of an Object. If Class B is a child of class A, then there can be a property in Class B that refers to which A object contains it. When your DataContext is set on your top level stackpanel, your first child can have something like DataContext="{Binding Parent}" where parent is the property that refers to ClassA.
Just set your DataContext in the top level stackpanel to the ClassA binding, leave it blank for the first child, and set it to your b property for each successive stackpanel.
Please let me know if I understood your right. I may need some more background on your program and problem.
Also, it is better to copy/paste real code than type it out as you go. Real code often gives better context to the problem.