I have the following ItemTemplate:
<ItemsControl ItemsSource="{Binding Topics}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,0">
<TextBlock Text="{Binding FallbackValue='topic name', Converter={StaticResource topicToStrConverter}}"
Margin="10,0"
VerticalAlignment="Center" />
<Button HorizontalAlignment="Right">
<Image Source="Images/appbar.cancel.rest.png" />
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I would like to right-align all of the buttons regardless of the length of their corresponding text, but I’m not sure how to do it.
I’m using Silverlight 4.
Your panel doesn’t have a set length, so there’s nothing to define where you want the right edge to be. If you put the items into a StackPanel or Grid with a fixed Width, you’ll see the behavior you expect.