невозможно перетащить пользовательский ScrollViewer в WrapPanel внутри ItemsPanelTemplate - PullRequest
0 голосов
/ 23 ноября 2011

Невозможно перетащить полосу прокрутки после реализации пользовательского прокрутки в списке в пользовательском контроле.

хорошо работает для других пользовательских контроллеров, имеющих список.

Единственная разница между пользовательскими элементами управления - это 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>

1 Ответ

0 голосов
/ 23 ноября 2011

В вашем примере 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>

Или вы можете использовать UniformGrid и управлять им с помощью свойства Columns или Rows.

...