Replies: 3 comments
-
Try NamedControls binding. Relative source uses visual tree and your Popup isn't part of that tree. |
Beta Was this translation helpful? Give feedback.
-
What do you mean NamedControls binding? I forgot to say. It only works with
Unfortunately, the |
Beta Was this translation helpful? Give feedback.
-
I can't reproduce it. Please note that Tip For binding to other controls DataContext: https://docs.avaloniaui.net/docs/guides/data-binding/binding-to-controls#binding-to-a-named-control If the issue persists, please file a minimal sample to reproduce. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I'm building a customizable toolbar like MS Word Toolbar. My concept is a lot of XAML and less code. It actually worked. Some controls like MenuFlyout, which I have known for a long time, always have issues.
The type of the property "Items" is
IEnumerable
ofTrayItem
. It works and contains two items. (See image below)But the binding is wrong. I looked with a debugger and found the issue. The DataContext of each item is
MainWindowsViewModel
insteadTrayItem
. Why is it there? Actually it's not true!!<MenuFlyout ItemsSource="{Binding Items, RelativeSource={...
I could solve the problem with just code, but I really want XAML. Unfortunately it doesn't work.
See screenhot:
![Image](https://private-user-images.githubusercontent.com/60543974/410924944-fb0dfa09-f00c-490c-98ab-98529290cd51.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNjEyNTAsIm5iZiI6MTczOTM2MDk1MCwicGF0aCI6Ii82MDU0Mzk3NC80MTA5MjQ5NDQtZmIwZGZhMDktZjAwYy00OTBjLTk4YWItOTg1MjkyOTBjZDUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDExNDkxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTczZmQwODk0YzczMDBlZDZlNmM1YjMwNDZiY2VhNzJjZTk3NWE3NDE2MGFlNzcyZTJmMDgwNmFhNDk3NjRiYzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.gDHcST4ZsEoKh4tUub0LhKQRQpZjSp37DahMBwoLxw4)
I only used the test converter for debugging and removed "EffectiveLabel" to look at it.
<Setter Property="Header" Value="{Binding Converter={StaticResource TestConverter}}"/>
It doesn't work with "RelativeSource" either.
It doesn't work with "RelativeSource" either.
However, when I add
$self
, the result showsMenuItem
with the wrong DataContextMainWindowsViewModel
. The DataContext should actually beTrayItem
.To Reproduce
I'm building my own toolbar. The name
Tray
is unrelated to SystemTray or ToolbarTray.1 Create a customizable toolbar
2 Add many items (
TrayItem
)3 Add two underlying items in a item (
TrayItem
)This item,
TrayItem
, automatically contains aDropDownButton
because it holds two items and does not have a command source.VisualTree shows this structure
Expected behavior
No response
Avalonia version
11.2.1
OS
Windows
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions