Reputation: 3407
I am building a WPF app that needs to display a list of filenames and their corresponding controls. Right now I have a Grid with some columns (i.e. Column 1 is a TextBlock
for a filename, column 2 is a CheckBox
indicating if this file is chosen, etc., and there is one row for each filename.)
It works except when a control in row i
is triggered, I have to search through the entire Grid to find other controls in row i
and change them accordingly. Is there a natural way to group the controls in a single row together so that it's easy to find one given another?
Note: By natural, I mean something builtin WPF. Constructing a UnionFind
for this wouldn't be considered natural.
Upvotes: 0
Views: 3133
Reputation: 219
FI suggest to use an ItemsControl. Something like this
<ItemsControl ItemsSource="{Binding Files}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding FileName}" />
<CheckBox IsChecked="{Binding IsSelected}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
With a List<MyModel>
or ObservableCollection<MyModel
of your model as the ItemsSource
public class MyModel
{
public string FileName { get; set; }
// And so on ...
}
Upvotes: 1