2011-11-23 23 views
0

在用戶控件的列表框上實現自定義滾動查看器後無法拖動滾動條。無法拖動ItemsPanelTemplate中的WrapPanel中的自定義滾動查看器

其工作正常的其他usercontrols有列表框。用戶控件之間

唯一的區別是WrapPanel

<!--ListBoxItem Style--> 
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem"> 
    <Setter 
     Property="FocusVisualStyle" 
     Value="{x:Null}" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListBoxItem"> 
       <Border 
        x:Name="ItemBorder" 
        BorderBrush="Transparent" 
        Background="Transparent" 
        BorderThickness="1" Margin="15"                       
        > 
        <ContentPresenter/> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger 
          Property="IsSelected" 
          Value="True"> 
         <Setter 
          TargetName="ItemBorder" 
          Property="Background" 
          Value="{StaticResource G2Brush}"/> 
         <Setter 
          TargetName="ItemBorder" 
          Property="BorderBrush" 
          Value="{StaticResource G4Brush}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
<!--ListBox Style--> 
<Style TargetType="{x:Type ListBox}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListBox}"> 
       <ScrollViewer x:Name="ScrollViewer"> 
        <ItemsPresenter/> 
       </ScrollViewer> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="ItemTemplate"> 
     <Setter.Value> 
      <DataTemplate> 
       <Border x:Name="border" Background="Transparent" Margin="2"> 
        <Grid Width="70" Height="70"> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="10"/> 
         </Grid.RowDefinitions> 
         <Border x:Name="borderImage" Background="Transparent" Grid.Row="0"> 
          <Image Source="{Binding Path=FilePath}" /> 
         </Border> 

         <TextBlock x:Name="ThumbFileName" Text="{Binding Path=FileName}" Grid.Row="1" 
            Style="{StaticResource ThumbFileName}" VerticalAlignment="Top" HorizontalAlignment="Left" 
            TextTrimming="CharacterEllipsis"            
            /> 
        </Grid> 
       </Border> 
       <DataTemplate.Triggers> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter TargetName="borderImage" Property="BorderBrush" Value="{StaticResource B1Brush}" /> 
         <Setter TargetName="borderImage" Property="BorderThickness" Value="1" /> 
         <Setter TargetName="ThumbFileName" Property="Foreground" Value="{StaticResource B1Brush}" /> 
        </Trigger> 
       </DataTemplate.Triggers> 
      </DataTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="ItemsPanel"> 
     <Setter.Value> 
      <ItemsPanelTemplate > 
       <WrapPanel Margin="10" 
          Background="Red" 
          /> 
      </ItemsPanelTemplate> 
     </Setter.Value> 
    </Setter> 
    <Setter 
     Property="ScrollViewer.HorizontalScrollBarVisibility" 
     Value="Disabled"/> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
</Style> 

    <Grid Background="Transparent"> 
      <ListBox x:Name="reportListViewControl" 
        Background="Transparent" 
        Foreground="{StaticResource G4Brush}" 
        BorderThickness="0" 
        Style="{StaticResource ListBoxStyle}" 
        ItemContainerStyle="{StaticResource ListBoxItemStyle}" 
        Drop="reportListViewControl_Drop" 
        SelectionMode="Extended"     
        SelectionChanged="reportListViewControl_SelectionChanged" 
        AllowDrop="True"> 
      </ListBox> 
     </Grid> 
+0

你在說什麼「定製ScrollViewer」? 您將ItemsPanel更改爲'WrapPanel'。你能指望什麼? – icebat

+0

我在app.xaml – suman

+0

中添加了自定義滾動查看器樣式所以問題出在這個自定義ScrollViewer中?那麼你爲什麼不向我們展示它的代碼呢? – icebat

回答

0

在您的例子WrapPanel採取一切需要,以顯示其項目的空間。要啓用滾動條可以通過其母公司的大小,ListBox限制它:

<ItemsPanelTemplate> 
    <WrapPanel Margin="10" Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" 
       Height="{Binding ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"/> 
</ItemsPanelTemplate> 

或者你可以使用UniformGridColumnsRows屬性來控制它。

+0

我已經嘗試了上面的代碼,但它沒有工作 – suman

+0

問題可能出現在'ListBox'本身,如果它獲取所有需要的空間而不需要顯示滾動條。它的父母控制是什麼? – icebat

+0

其父控制是網格。我已經在上面添加了代碼供您參考 – suman