2009-09-23 2 views
0

모서리가 둥근 스타일로 목록 상자가 있습니다. 특정 목록 상자와 관련된 목록 상자 안에 도구 모음을 추가하고 싶습니다. 현재 목록 상자가 포함 된 표 안의 도구 막대를 추가하면 도구 막대의 높이에 따라 행의 마지막 항목과 겹칩니다. 누구든지 이것을 구현하는 가장 좋은 방법에 대한 아이디어가 있습니까? 목록 가장자리의 모양과 일치하는 테두리 컨트롤을 만든 다음 기본 테두리 안에 테두리가없는 스타일이있는 목록 상자를 아래쪽에 도구 모음과 겹쳐서 배치 할 수 있다는 것을 알고 있지만 더 나은 방법이 있기를 바라고 있습니다. 내 현재 목록 스타일을 유지하고 모든 목록 상자 항목을 숨기지 않는 목록 상자의 아래쪽에 도구 모음을 배치하십시오.WPF에서 목록 상자 안쪽의 아래, 위, 왼쪽 또는 오른쪽에 도구 모음을 추가하는 방법은 무엇입니까?

감사합니다,

답변

1

나는 완전히 확실하지에 따라,하지만 난 당신이 몇 가지 옵션이 있다고 생각 :

  1. 아마 ListBox을 확장하고 ToolBar을 설정하는 속성을 추가하는 컨트롤을 작성함으로써 ListBox 템플릿에 ToolBar 통합을 항목.
  2. ListBoxBorder을 끄고 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

0

대부분의 경우 당신은 일이 시각적으로 중복되는 경우 뭔가 코드에서 잘못된 선언합니다. ListBox를 Grid.Row = "0"으로 선언하고 도구 모음을 Grid.Row = "1"(또는 비슷한 항목)로 두어야합니다. This MSDN article은 그리드 레이아웃을 잘 설명합니다.

ListBoxItem이 데이터 바인딩되지 않은 경우 사용자 지정 스타일이있는 ListBoxItem을 목록의 마지막 항목으로 추가하면됩니다. 그렇지 않으면 DataTemplateSelector을 사용하여 안에 바인딩 된 콘텐츠를 기반으로 항목 스타일의 서식을 지정할 수 있습니다.

관련 문제