2011-11-15 145 views
1

我有自定义视图这里是具有Wrappanel与垂直orietiation水平滚动不显示在WrapPanel WPF

的问题是,它并没有显示水平滚动条...

这里是链接代码...
Code for what i am trying

Here whats it looks like now

我的自定义视图样式

<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type CustomView:PlainView}, 
            ResourceId=ImageView}"   
     TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}"> 

    <Setter Property="ItemContainerStyle" Value="{Binding (ListView.View).ItemContainerStyle, RelativeSource={RelativeSource Self}}" /> 
    <Setter Property="ItemTemplate" Value="{Binding (ListView.View).ItemTemplate, RelativeSource={RelativeSource Self}}" /> 
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> 
    <Setter Property="ScrollViewer.CanContentScroll" Value="true" /> 
    <Setter Property="VerticalContentAlignment" Value="Center" /> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    <Setter Property="FontFamily" Value="Trebuchet MS" /> 
    <Setter Property="FontSize" Value="12" /> 
    <Setter Property="BorderBrush" Value="#FFB1703C" /> 
    <Setter Property="BorderThickness" Value="1" /> 
    <Setter Property="Padding" Value="1" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListView}"> 
       <Border Name="bd" 
         Margin="{TemplateBinding Margin}"        
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1"> 
        <Border.Background> 
         <LinearGradientBrush StartPoint="0.056,0.5" EndPoint="1.204,0.5"> 
          <GradientStop Offset="0" Color="#FFFFFFFF" /> 
          <GradientStop Offset="1" Color="#FFD4D7DB" /> 
         </LinearGradientBrush> 
        </Border.Background> 

        <ScrollViewer Name="plainViewScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" Margin="{TemplateBinding Padding}"> 
         <WrapPanel Focusable="False" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"          Height="{Binding ActualHeight, 
                RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
            MinWidth="{Binding (ListView.View).MinWidth, 
                 RelativeSource={RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type ListView}}}" 
            IsItemsHost="True" 
            ItemWidth="{Binding (ListView.View).ItemWidth, 
                 RelativeSource={RelativeSource Mode=FindAncestor, 
                         AncestorType={x:Type ListView}}}" 
            KeyboardNavigation.DirectionalNavigation="Cycle" 
            Orientation="Vertical" /> 
        </ScrollViewer> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

我的ListView样式

<Style TargetType="{x:Type ListView}"> 

    <Setter Property="SnapsToDevicePixels" Value="true" /> 
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> 
    <Setter Property="ScrollViewer.CanContentScroll" Value="True" /> 
    <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
    <Setter Property="VerticalContentAlignment" Value="Center" /> 
    <Setter Property="FontFamily" Value="Trebuchet MS" /> 
    <Setter Property="FontSize" Value="12" /> 
    <Setter Property="BorderBrush" Value="{DynamicResource ControlBorderBrush}" /> 
    <Setter Property="BorderThickness" Value="1" /> 
    <Setter Property="Padding" Value="1" /> 
    <Setter Property="IsTabStop" Value="False" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ListView}"> 
       <Grid> 
        <Border x:Name="Border" 
          Background="{DynamicResource ControlBackgroundBrush}" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}" 
          CornerRadius="1"> 
         <ScrollViewer Margin="{TemplateBinding Padding}"> 
          <WrapPanel Focusable="False" Width="{Binding ActualWidth, 
                RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
            Height="{Binding ActualHeight, 
                RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
            MinWidth="{Binding (ListView.View).MinWidth, 
                 RelativeSource={RelativeSource Mode=FindAncestor, 
                        AncestorType={x:Type ListView}}}" 
            IsItemsHost="True" 
            ItemWidth="{Binding (ListView.View).ItemWidth, 
                 RelativeSource={RelativeSource Mode=FindAncestor, 
                         AncestorType={x:Type ListView}}}" 
            KeyboardNavigation.DirectionalNavigation="Cycle" 
            Orientation="Vertical" /> 
         </ScrollViewer> 
        </Border> 
        <Border x:Name="DisabledVisualElement" 
          Background="#A5FFFFFF" 
          BorderBrush="#66FFFFFF" 
          BorderThickness="1" 
          IsHitTestVisible="false" 
          Opacity="0" /> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter TargetName="DisabledVisualElement" Property="Opacity" Value="1" /> 
        </Trigger> 
        <Trigger Property="IsGrouping" Value="true"> 
         <Setter Property="ScrollViewer.CanContentScroll" Value="false" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

的ListView

<ListView Name="lv" 
       Grid.Row="1" 
       Height="Auto" 
       Width="Auto" 
       IsTextSearchEnabled="True"     
       ItemsSource="{Binding Path=Persons}" 
       KeyboardNavigation.DirectionalNavigation="Cycle" 
       SelectedItem="{Binding Path=SelectedPerson}" 
       SelectionMode="Single" 
       View="{StaticResource ResourceKey=plainView}" 
       >    
       </ListView> 

自定义视图资源

<DataTemplate x:Key="centralTile"> 

    <StackPanel Width="80" 
       Height="40" 
       KeyboardNavigation.AcceptsReturn="True" 
       Focusable="True">    
     <Grid>    
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="30" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <Button Command="{Binding Path=DataContext.KeyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}" 
          CommandParameter="{Binding}"> 
       <TextBlock Text="{Binding Path=Name}" /> 
      </Button> 
      <Image Grid.Column="1" Source="Water lilies.jpg" />     
     </Grid> 
     <TextBlock HorizontalAlignment="Center" 
        FontSize="13" 
        Text="{Binding Path=Name}" /> 
    </StackPanel> 
</DataTemplate> 
<CustomView:PlainView x:Key="plainView" 

         ItemTemplate="{StaticResource ResourceKey=centralTile}" 
         ItemWidth="100" /> 

我的ListView是一个窗口内托管..

+1

什么是您的自定义控制托管的内部?这可能是问题。 –

+0

我已添加我的控制和视图 – Ankesh

+0

@KentBoogaart我应该添加代码为PlainView是必需的? – Ankesh

回答

2

WrapPanel

ScrollViewers意味着滚动内容比ViewPort较大取出Width属性,您WidthWrapPanel结合限制了面板实际的ScrollViewer的视宽的尺寸。这意味着ScrollViewer无法滚动,因此它不会显示ScrollBar。

<ScrollViewer Margin="{TemplateBinding Padding}"> 
    <WrapPanel Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" 
       Focusable="False" 
       IsItemsHost="True" 
       ItemWidth="{Binding (ListView.View).ItemWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}" 
       KeyboardNavigation.DirectionalNavigation="Cycle" 
       Orientation="Vertical" /> 
</ScrollViewer> 

另外,我会强烈建议等工具来Snoop用于调试XAML的问题。它也告诉我你的MinHeight绑定无效,所以我删除它。

+0

它工作谢谢... :) – Ankesh

1

这事实上,您已将WrapPanel的宽度限制为视口的宽度。这意味着它只会和视口一样大,这是用户在不滚动的情况下可以看到的部分。因此,ScrollViewer认为没有可滚动的内容。

+0

我最近从'Width =“{Binding ActualWidth,RelativeSource = {RelativeSource AncestorType = ScrollContentPresenter}}''改变了它,但结果是一样的....没有横向滚动:( – Ankesh

+0

@ adcool2007:那么请更新您的问题! –

+0

下面是我试图在代码的链接...它具有样本项目...我也补充说,在这个问题:http://www.filefat.com/mkqysgiam2ev – Ankesh

0

不绑定的WrapPanel的宽度。只要绑定高度。

+0

仍然没有运气我删除'MinWidth =“{结合(ListView控件。视图).MinWidth,的RelativeSource = {的RelativeSource模式= FindAncestor,AncestorType = {X:类型的ListView}}} “''&&宽度=”{结合ActualWidth的,的RelativeSource = {的RelativeSource AncestorType = ScrollContent演示者}}“'从风格...仍然相同 – Ankesh

+0

查看链接在问题中添加(示例项目) – Ankesh