开发者

WPF set grid row to a dynamic XAML object using binding

开发者 https://www.devze.com 2023-02-13 07:53 出处:网络
I want have the content 开发者_如何学Cof a Grid\'s row (not DataGrid) bound to a given DataContext property. In others words, I want that the UserControl that appear in, lets say... row 0 of my Grid,

I want have the content 开发者_如何学Cof a Grid's row (not DataGrid) bound to a given DataContext property. In others words, I want that the UserControl that appear in, lets say... row 0 of my Grid, change when the DataContext property XX change from an UserControl to another UserControl. Any idea how do that?

What I'm trying to achieve is a loosely couple UI consisting of a Shell (main window) with placeholders, but with the capability to allow the content of such placeholders be changed from any of the placeholders, How? well, binding some placeholder controls's Commands to the Shell DataContext's Commands (the ShellViewModel) that is by hierarchy the DataContext of all controls of any placeholder that don't overwrite the DataContext property, then inside the implementation of such commands change XX.

More specifically, I want that the navigation controls (UI) of my applications can be easily changed without affect the semantic of the navigation, and the only thing that come to my newbie mind after read about MVVM is the above approach. Do you have a better idea? Is that correct or is too loosely couple ;)

I Added this part after the first reply:

Data template don't fill the bill. Why? Well, simple, with data template the Shell must know at front all the possible part of the UI elements that will compose the application UI (the views that take UserControls form normally) and the idea here is avoid that. The idea is have a Shell with placeholders, and that the Shell expose Commands through its DataContext (the Shell's ViewModel) to any of the UNKNOWN AT FRONT UIs components that will fill such placeholders. Such commands can be saw as a kind of API/Interface used to interact with the navigation system.

After research more, I get an idea so one ANSWER can be some thing like the follow:

<ContentControl Grid.Row="0">
    <Binding Path="CurrentView"/>
 </ContentControl>


I'm not sure if I understand your question fully, but a data template selector might be what you're looking for. In your case the returned template would be changed based on the current DataContext, the template would contain the repspective UserControl

0

精彩评论

暂无评论...
验证码 换一张
取 消