WPF 绑定 Grid 上的 SharedSizeGroup 不起作用
我正在开发一个 WPF 应用程序来练习 MVVM。我需要有 4 个网格,所有网格都只有两列 - 一列用于“显示”控件(带有字段名称的 TextBlock/RadioButton),另一列用于“值”控件(表示字段值所需的任何控件) )。
另一个用户控件中的每个网格,我需要使它们的所有第一列保持同步,因此“值”控件将在屏幕上延伸,而共享大小的“显示”控件将具有不改变的自动宽度。
如果我使用常量名称设置 SharedSizeColumn,则所有网格都处于完美且美观的同步状态,但我需要通过与视图模型绑定来设置 SharedSizeColumn,因为包含这些网格的某些用户控件在选项卡式视图模型之间共享以供重用,跨选项卡/视图模型我不希望网格同步。 当我使用绑定设置 SharedSizeGroup 时,所有网格中的 2 列就像根本没有设置 SharedSizeGroup 一样,我什至尝试使用 BindingOperations 通过代码设置绑定,但仍然没有运气。
知道如何成功绑定 SharedSizeGroup,或者防止 SharedSizeGroup 在重用相同用户控件的选项卡之间共享的其他解决方案吗?
I am working on a WPF application to practice MVVM. I have a need to have 4 grids, all have only two columns - one for a "display" control (TextBlock/RadioButton with a field's name) and the other for "value" control (any control needed to represent the value of the field).
Each grid in another user control, and I need to have all of their first columns to be in sync, so the "value" controls will stretch over the screen while the "display" controls that share size will have automatic width that doesnt change.
If I set SharedSizeColumn with constant name, all the grids are in perfect and good looking sync, but I need to set the SharedSizeColumn via binding with my view model, because some user controls that contain those grids are shared between tabbed view models for reuse, and across tabs/view models I dont want the grids to be synchronized.
When I set SharedSizeGroup with bindings, the 2 columns in all the grids act like there is no SharedSizeGroup set at all, I've even tried setting the binding via code using BindingOperations and still no luck.
Any idea how to successfully bind SharedSizeGroup, or another solution for preventing the SharedSizeGroup to be shared amongst tabs that reuse the same user control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是使用
SharedSizeGroup
进行数据绑定的完整工作示例。标记:
和代码隐藏:
以及原始视图模型:
这就是它的样子:
它显示了红色和蓝色的柱子排列在一起。
Here is a complete working sample of using
SharedSizeGroup
with data binding.The markup:
and the code-behind:
and the primitive view-model:
and this is what it looks like:
which shows the red and blue columns lined up.