나는 완전히 확실하지에 따라,하지만 난 당신이 몇 가지 옵션이 있다고 생각 :
- 아마
ListBox
을 확장하고 ToolBar
을 설정하는 속성을 추가하는 컨트롤을 작성함으로써 ListBox
템플릿에 ToolBar
통합을 항목.
ListBox
의 Border
을 끄고 Border
주위에 ToolBar
을 포함하여 고정하십시오.
2 조금 더 쉽고 원하는 것일 수 있습니다.
예 1
(내가 여기에 서브 클래스 목록 상자를 귀찮게하지 않았다 - 난 그냥 대신 일부 도구 모음 항목 하드 코딩)
<Grid Margin="10">
<ListBox>
<ListBox.Template>
<ControlTemplate TargetType="ListBox">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="1,1,1,1" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" Name="Bd" SnapsToDevicePixels="True" CornerRadius="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ToolBarTray Background="White">
<ToolBar Band="1" BandIndex="1">
<Button>
Cut
</Button>
<Button>
Copy
</Button>
<Button>
Paste
</Button>
</ToolBar>
<ToolBar Band="2" BandIndex="1">
<Button>
Undo
</Button>
<Button>
Redo
</Button>
</ToolBar>
</ToolBarTray>
<ScrollViewer Grid.Row="1" Padding="{TemplateBinding Control.Padding}" Focusable="False">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</ScrollViewer>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="Panel.Background" TargetName="Bd">
<Setter.Value>
<DynamicResource ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="ItemsControl.IsGrouping" Value="True">
<Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ListBox.Template>
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
</ListBox>
</Grid>
예 2
<Grid Margin="10">
<Border CornerRadius="5" BorderThickness="1" BorderBrush="Black" Padding="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ToolBarTray Background="White">
<ToolBar Band="1" BandIndex="1">
<Button>
Cut
</Button>
<Button>
Copy
</Button>
<Button>
Paste
</Button>
</ToolBar>
<ToolBar Band="2" BandIndex="1">
<Button>
Undo
</Button>
<Button>
Redo
</Button>
</ToolBar>
</ToolBarTray>
<ListBox Grid.Row="1" BorderThickness="0">
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
</ListBox>
</Grid>
</Border>
</Grid>
의를
두 경우 모두 비슷한 결과가 나타납니다.
alt text http://img42.imageshack.us/img42/372/screenshotof.png