Repository navigation
[Fix] #505 - [LayoutItem] Let the CanClose style setter win over the … - #633
Merged
sharpSteff merged 2 commits intoAug 8, 2026
Merged
Conversation
… over the model value SetDefaultBindings seeded CanClose from the layout model with a plain assignment, which stamps a local value onto the LayoutItem. A local value outranks a Style setter, so <Setter Property="CanClose" Value="False"/> was silently discarded whenever the container style arrived after the item already existed. That is exactly what happens when the DataContext is declared in XAML: the DocumentsSource binding resolves while the window is parsed, so the documents - and their LayoutItems - are created before the parser reaches LayoutItemContainerStyle(Selector). Assigning the DataContext in code behind produces the opposite order, which is why the setter appeared to work there. Seeding the value with SetCurrentValue keeps the model sync while leaving the local-value slot free, so a style setter applied later still wins and still propagates back to the layout model. IsSelected, IsActive and the anchorable Visibility are deliberately left as plain assignments: those are commonly bound Mode=TwoWay in container styles and SetCurrentValue does not write back through a two-way binding. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019x4VAXcunCRWcKZCcumfFZ
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.
Closes #505
The bug
LayoutItem.SetDefaultBindings()seededCanClosefrom the layout model with a plain assignment:A local value outranks a
Stylesetter in WPF's precedence order, so<Setter Property="CanClose" Value="False"/>was silently discarded whenever the container stylearrived after the item already existed.
Which of the two happens first is decided by where the
DataContextis assigned — which is exactlywhy the issue reports it as a DataContext problem:
DocumentsSourceresolves afterLayoutItemContainerStyle(Selector)hasbeen set, so the style setter applies to a fresh item and the trailing sync merely re-writes the
same
false.<Window.DataContext>in XAML (broken): the binding resolves during parsing, so the documents— and their
LayoutItems — exist before the parser reaches the style property. The localtrueis already in place and the setter never takes effect. The close button stays visible.
The fix
One line in
Controls/LayoutItem.cs— seed the value withSetCurrentValueinstead:This keeps the model sync but leaves the local-value slot free, so a style setter applied later
still wins and still propagates back to the layout model through
OnCanCloseChanged.IsSelected,IsActiveandLayoutAnchorableItem'sVisibilitysit on adjacent lines with thesame latent problem but are deliberately left as plain assignments: those are commonly bound
Mode=TwoWayin container styles (seesource/MVVMTestApp/MainWindow.xaml), andSetCurrentValuedoes not write back through a two-way binding, so converting them would quietly break model
write-back. Happy to revisit that separately if you'd prefer them changed too.
Tests
LayoutItemContainerStyle/LayoutItemContainerStyleSelectorhad no test coverage at all.