3

Is there any way of dynamically binding a list buttons to a WrapPanel as well as their events?

akrisanov
  • 3,212
  • 6
  • 33
  • 56

1 Answers1

7

I'm not too sure if this is correct for what you are wanting to do, but it sounds very similar:

The XAML from the link above is as follows:

<ItemsControl x:Name="activitiesControl" Margin="10">
    <ItemsControl.Template>
        <ControlTemplate>
            <WrapPanel  Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
                    FlowDirection="LeftToRight" IsItemsHost="true">
            </WrapPanel>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Style="{DynamicResource ActionButton}" HorizontalAlignment="Right" Margin="5" 
                Content="{Binding Value}" Width="200" 
                Command="{Binding Path=ViewModel.ActionTypeCommand, 
                    RelativeSource={RelativeSource Mode=FindAncestor,     
                AncestorType=local:CustomerEditView}}" CommandParameter="{Binding Key}"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Kyle Rosendo
  • 25,001
  • 7
  • 80
  • 118
  • I'm sure I'm showing my ignorance here (beginner to WPF and Xaml at the moment), but I can't see how ItemsControl finds the property ItemsSource (which I believe is mentioned in the source article). – tobriand Oct 16 '14 at 15:14
  • 2
    I'm an idiot. For anyone who's new to WPF and wants to avoid my confusion, ItemsControl has a property (ItemsSource) that can be assigned at runtime, NOT via a property on the associated VM. Presumably, this also means that adding the property `ItemsSource="{Binding MyList}"` would probably work... – tobriand Oct 16 '14 at 15:17