업데이트: 2007년 11월
컨테이너 내부의 컨트롤 크기가 각기 다를 수 있습니다. 예를 들어 StackPanel 내의 Button 크기는 StackPanel의 전체 너비에 맞춰 정해지지만 ListBox 내의 Button 크기는 Button의 콘텐츠 크기에 맞춰 정해집니다. ListBox 내의 Button 컨트롤을 사용 가능한 공간에 꽉 차게 만들려면 ListBoxItem을 늘이는 스타일을 만들고 해당 스타일을 ListBox의 ItemContainerStyle에 적용해야 합니다. 다음 예제에서는 이 작업을 수행하는 방법을 보여 줍니다.
예제
Dim style As Style = New Style()
style.Setters.Add(New Setter(ListBoxItem.HorizontalContentAlignmentProperty, _
HorizontalAlignment.Stretch))
Dim lb As ListBox = New ListBox()
lb.ItemContainerStyle = style
Dim lbi1 As ListBoxItem = New ListBoxItem()
Dim btn As Button = New Button()
btn.Content = "Button as styled list box item."
lbi1.Content = (btn)
lb.Items.Add(lbi1)
Style style = new Style(typeof(ListBoxItem));
style.Setters.Add(new Setter(ListBoxItem.HorizontalContentAlignmentProperty,
HorizontalAlignment.Stretch));
ListBox lb = new ListBox();
lb.ItemContainerStyle = style;
ListBoxItem lbi1 = new ListBoxItem();
Button btn = new Button();
btn.Content = "Button as styled list box item.";
lbi1.Content = (btn);
lb.Items.Add(lbi1);