I have a View with an ItemsControl that contains a Grid. The ItemsControl is bound to an ObservableCollection.
Each Thing has the following properties: Name (string), Value (string), LocationDictionary(tabid(string), Location)
Each Location has the following properties: Col(int), Row(int), TabId(string), IsVisible(bool)
The View is in a Tab on a WPF UserControl.
Is it possible in XAML to use the Dictionary on Thing to determine the Row and Column to place Thing in the ItemsControl.ItemContainerStyle Setter?
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value={Binding Path=LocationsDictionary[thisTabId].Row}" />
<Setter Property="Grid.Column" Value={Binding Path=LocationsDictionary[thisTabId].Col}" />
</Style>
Can the thisTabId variable be set at the view level and used in the Binding Path in the ItemsControl?
The goal here is to be able to place Things in the grid, it can only exist once, but can exist on other tabs with the same View. I have things working for one grid with the Row and Col on Thing, but when applied to a second grid, Things end up in the same place on each grid/tab. Thing 2 ends up in the same grid cell locaiton on each tab.
The Dictionary is one way we came up with to give a Thing multiple location attributes so it can exist on multiple tabs in different places.
You can't do something like this in pure XAML unless thisTabId
is a constant:
{Binding Path=LocationsDictionary[thisTabId].Row}
In other words, thisTabId
cannot be a dynamic value that changes for each item in the ItemsControl
. If you want to this, you could use a multi value converter that binds to both the LocationsDictionary
property and the thisTabId
property and returns LocationsDictionary[thisTabId].Row
or LocationsDictionary[thisTabId].Column
.