Xaml - 将现有控件添加到网格

发布于 2024-08-11 10:35:20 字数 573 浏览 2 评论 0原文

尝试使用 MVVM 进行开发:

我有在我的 ViewModel 中创建的 Csla.PropertyStatus 控件。 我想将它添加到 xaml 中(我认为是通过绑定)并在那里设置一些附加属性(例如目标)。

我不知道我怎么能做到这一点,即使这是可能的。

我一直在寻找类似的东西,

<csla:PropertyStatus Instance="{Binding Path=MyStatus}" 
                     Target="{Binding ElementName=txtTextBox}" 
                     Grid.Column="2" Grid.Row="0"/>

这可能以某种方式吗?...我需要在 ViewModel 中创建它,因为我需要设置一些不允许视图(XAML)知道的属性。

编辑: 我所说的属性是模型。 PropertyStatus 需要对业务对象的引用才能执行验证。 但考虑到 MVVM 的范式(或者按照我的理解),视图应该与模型解耦,并且应该只知道 ViewModel。不过,我可能会改变这种方法......

Trying to develop using MVVM:

I have this Csla.PropertyStatus control that is created in my ViewModel.
I want to add it in the xaml (via binding, i think) and set some additional properties there (such as the target).

I don't know how i could do that, not even if that is possible.

I was looking for something like

<csla:PropertyStatus Instance="{Binding Path=MyStatus}" 
                     Target="{Binding ElementName=txtTextBox}" 
                     Grid.Column="2" Grid.Row="0"/>

Is that possible somehow?... i NEED to create it in the ViewModel because i need to set some property that the view (XAML) is not allowed to know about.

Edit:
The property i'm talking about is the model. The PropertyStatus needs a reference to the business object to perform the validation.
But considering the paradigm of MVVM (or as i understand it), the view should be decoupled from the model, and should only know about the ViewModel. I might change that approach, though...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅冇旳回忆 2024-08-18 10:35:20

你不能这样做。顺便说一句,视图都是关于 UI 控件及其属性的,因此说视图不允许“了解”其元素之一的属性有点……极端。在这里描述您想要完成的任务可能有助于为您提供一个不错的答案。

You CAN'T do this. BTW, the view is all about UI controls and their properties, so saying the view is not allowed to "know about" a property on one of its elements is a bit... extreme. A description of what you are trying to accomplish here might help in providing you with a decent answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文