How can a ListBoxItem property be set in Silverlight at runtime?
- by sympatric greg
Given this XAML, I need to resize the userControl in response to user input. How can I set a new width for ListBoxItem (or perhaps the StackPanel)?
<ScrollViewer x:Name="ScrollViewer" Margin="0" BorderBrush="Transparent" Width="165"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
<ListBox x:Name="AttributeListBox" ItemsSource="{Binding Attributes}" BorderBrush="Red" Width="160"
Foreground="AntiqueWhite" Background="Transparent" IsEnabled="False" HorizontalAlignment="Stretch">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Width" Value="150"/>
<Setter Property="Margin" Value="0,-2,0,0"/>
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="Template" Value="{StaticResource ListBoxItemSansFocus}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="ListBoxItemStackPanel" HorizontalAlignment="Stretch"
Orientation="Vertical" >
<TextBlock FontSize="10" Text="{Binding Key}" Foreground="White"
FontWeight="Bold" HorizontalAlignment="Stretch"
Margin="2,0,0,0" TextWrapping="Wrap"/>
<TextBlock FontSize="10" Text="{Binding Value}" Foreground="White" Margin="6,-2,0,0" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>