Hi!
I have a typical MVVM scenario: I have an ItemsControl
bound to an ObservableCollection
of StepsViewModels. I define a DataTemplate so that StepViewModels are rendered as StepViews. The same happens in the StepView: I have an ItemsControl
to an ObservableCollection
of ParameterViewModels with a DataTemplate to render them as ParameterViews.
My problem is: I have to refresh the ItemsControl
to render items added and remove items. I can refresh the ItemsControl
with StepViews, because I have access to it and can call ItemsControl.Items.Refresh(). But how can I access the StepViews so I can call a Refresh method? ItemsControl Items are StepViewModels...
Here is the code:
<UserControl x:Class="mylib.EditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:mylib">
<UserControl.Resources>
<DataTemplate DataType="{x:Type my:StepViewModel}">
<my:StepView HorizontalAlignment="Stretch"/>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="27"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1" VerticalAlignment="Top">
<StackPanel Orientation="Vertical">
<TextBlock Name="lblHelpRefresh" Margin="0 7 0 7" Visibility="{Binding HelpVisible}"
VerticalAlignment="Center" HorizontalAlignment="Center"
FontSize="9pt" Foreground="#949494"
Text="Please click refresh to reload this list"/>
<ItemsControl Name="stkStepContent"
ItemsSource="{Binding Steps}"/>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
How can I access the StepView controls that render the stkStepContent Items?