Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add an extra item to a data bound ItemsControl in XAML?

Tags:

I have an ItemsControl that is data bound to a list of decimals. I need to add one extra control to the ItemsControl (an option to specify the number manually). Is there a way to do this in XAML? I know I can manually add the item in the code behind, but I'm trying to understand WPF a little better and want to see if there is a declarative way to do it.

Note that modifying the list I'm binding to so that it includes the extra button (possibly by changing to a list of strings instead of decimals) isn't a good alternative because I want to attach a command to that last button.

Also, adding an extra button after the ItemsControl isn't a good option either, because my control uses a UniformGrid and I want my extra control in that same grid.

Here is my XAML:

<ItemsControl ItemsSource="{Binding PossibleAmounts}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Name="ButtonsGrid">
            </UniformGrid>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button>
                <TextBlock Text="{Binding StringFormat='\{0:C\}'}"/>
            </Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

Basically, I want one more button in the UniformGrid.