Try this: ItemsSource="{x:Static self:GlobalElements.ocWidgets}"
.
How to Use a Collection in Multiple Windows
RogerSchlueter-7899
1,426
Reputation points
I have a Public Module named "GlobalElements" that contains a Public ObservableCollection(Of Widget) named ocWidgets. I want to use ocWiddgets as a ItemsSource for ComboBoxes on multiple wpf windows. In the XAML for such a window I tried what seemed to me to be the logical code:
<Window
xmlns:self="clr-namespace:PIM"
....>
<MyComboBox
ItemsSource="{Binding Path=self:GlobalElements.ocWidgets}"
.... />
but that gives the error "Invalid property path syntax". Other permutations of that syntax yield the same result.
For now I just make a copy of ocWidgets in each wpf window and use that copy for the ItemsSource. But surely there is a way to just directly reference ocWidgets in the Module?
Accepted answer
-
Viorel 121.3K Reputation points
2024-10-05T21:09:44.71+00:00