Basic support for DataContext={resource: ...}#1392
Merged
tomasherceg merged 17 commits intomainfrom Mar 16, 2025
Merged
Conversation
bcdd52d to
e885da2
Compare
d99fb15 to
dca0a1b
Compare
a9193f7 to
2fa5063
Compare
efbaf1e to
3ee2344
Compare
3ee2344 to
14a7721
Compare
exyi
added a commit
that referenced
this pull request
Dec 7, 2022
problem was that that BindingHelper.FindDataContextTarget assumed there was one more data context layer since we used set data context type and DataContext on different controls. Because of that command client-side and server-side data context paths didn't match. Technically, this is a glitch of BindingHelper, not HierarchyRepeater, but "fixing" BindingHelper will break many things and it's hopefully going to be done in #1392
exyi
added a commit
that referenced
this pull request
Dec 7, 2022
problem was that that BindingHelper.FindDataContextTarget assumed there was one more data context layer since we used set data context type and DataContext on different controls. Because of that command client-side and server-side data context paths didn't match. Technically, this is a glitch of BindingHelper, not HierarchyRepeater, but "fixing" BindingHelper will break many things and it's hopefully going to be done in #1392
exyi
added a commit
that referenced
this pull request
Dec 21, 2022
problem was that that BindingHelper.FindDataContextTarget assumed there was one more data context layer since we used set data context type and DataContext on different controls. Because of that command client-side and server-side data context paths didn't match. Technically, this is a glitch of BindingHelper, not HierarchyRepeater, but "fixing" BindingHelper will break many things and it's hopefully going to be done in #1392
exyi
added a commit
that referenced
this pull request
Jan 4, 2023
Part is taken from #1392 which won't be merged for a while.
exyi
added a commit
that referenced
this pull request
Feb 1, 2023
Part is taken from #1392 which won't be merged for a while.
14a7721 to
dd7cf40
Compare
88d7168 to
3019446
Compare
e7708ec to
10002de
Compare
exyi
commented
Feb 7, 2025
051a7ad to
a9b9783
Compare
This functionality is essential for server-side only rendering, but this patch is only the groundwork - we still need to add support to Repeater and possibly other controls. The design is fairly simple - we allow resource binding in data context and track that this data context does not exist client-side (see the new ServerSideOnly property). Using this server-only data context is not allowed in value and staticCommand bindings. Note that using a value binding inside the resource-bound control is allowed, it just cannot reference `_this`. Since the context does not exist client-side, we then translate _parent into $data instead of $parent.
630c5b9 to
bc1e371
Compare
* ExpectedType property can now be null, when the assigned property is unknwon:
- this means that CreateBinding will actually create a strongly
typed instance, instead of just ValueBindingExpression<object> or similar
* AutoUI uses props.Property instead of CreateValueBinding where possible
…property This avoids being too sensitive to the DataContextType property, which is often set incorrectly in our libraries (to hack around other issues, so not easily fixed). We therefore switch the IsServerSideOnly check to another dedicated property which needs to be set by Repeater and similar controls. This means that DataContext=resource compatibility will need some non-obvious hack, but code which doesn't do that will not be affected by the update to v5 in any way.
Some controls now need to allow resource bindings, but not hardcoded values (i.e. grid columns)
bc1e371 to
27ae8e1
Compare
tomasherceg
approved these changes
Mar 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This functionality allows server-only rendering - i.e. building static HTML based on viewmodel which is not necessarily sent to the client.
The design is fairly simple - we allow resource binding
in data context and track that this data context does
not exist client-side (see the new
ServerSideOnlyproperty).Using this server-only data context is not allowed in value
and
staticCommandbindings. Note that using a value bindinginside the resource-bound control is allowed, it just cannot
reference
_this. Since the context does not exist client-side,we then translate
_parentinto$datainstead of$parent.Repeater, GridView and HierarchyRepeater should all support this.