3

UserControl列挙型のすべての可能な値をaのように表示しRadioButtonて、ListBoxそのうちの1つを選択します。このコントロールがScrollViewerテキストボックスなどの他のコントロールとともに内部にあり、マウスホイールでスクロールしようとするとScrollViewer、マウスカーソルがEnumBox上にあるときにフォームがスクロールされません。

UIでは次のようになります。

UIのEnumBox

デモンストレーションでは、RadioButton背景が黄色で、WrapPanel背景が緑色です。マウスカーソルが色付きの領域内(たとえば、内WrapPanel)にある場合、マウスホイールによるスクロールは効果がありません。

EnumBoxのテンプレートは次のようになります。

  <UserControl.Template>
    <ControlTemplate TargetType="{x:Type clientsWpf:EnumBox}">
      <StackPanel>
        <GroupBox Header="{Binding Header, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}">
          <Border x:Name="InvalidBorder"  BorderBrush="Red" BorderThickness="0" >
            <ListBox x:Name="PART_ListBox" HorizontalAlignment="Left" KeyboardNavigation.DirectionalNavigation="Cycle" Background="Transparent" BorderThickness="0" SelectedValuePath="." SelectedValue="{Binding Path=SelectedValue, RelativeSource={RelativeSource AncestorType={x:Type clientsWpf:EnumBox}}}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
              <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                  <WrapPanel Orientation="Horizontal" Background="Green"/>
                </ItemsPanelTemplate>
              </ListBox.ItemsPanel>
              <ListBox.Resources>
                <Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}" >
                  <Setter Property="Template">
                    <Setter.Value>
                      <ControlTemplate>
                        <Border Background="Transparent" Background="Yellow">
                          <RadioButton Margin="3" Focusable="False" Content="{TemplateBinding ContentControl.Content,Converter={StaticResource enumValueDescriptionConverter}}" 
                                     IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" />
                        </Border>
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style>
              </ListBox.Resources>
            </ListBox>
          </Border>
        </GroupBox>
      </StackPanel>
    </ControlTemplate>
  </UserControl.Template>

、、、を設定ScrollViewer.VerticalScrollBarVisibility="Disabled"してみScrollViewer.CanContentScroll="False"ましたがListBox、効果はありませんでした。WrapPanelRadioButtonBorder

4つのコントロールすべてでイベントをキャッチしようとしましScrollBar.Scroll="WrapPanel_Scroll"たが、いずれもヒットしませんでした。

効果なしで設定SelectiveScrollingGrid.SelectiveScrollingOrientation="None"してみました。RadioButton

UIでのスクロールを妨げるものについて誰かが手がかりを持っていますか?

明確にするために:それはEnumBox内でスクロールすることではなく、フォーム全体をスクロールすることです。

4

2 に答える 2

3

問題は、ListBox独自のを持っていることScrollViewerです。のテンプレートをコピーしてListBox、埋め込まれたを削除しますScrollViewer

ScrollViewerコメントが埋め込まれた完全な例を次に示します。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <SolidColorBrush x:Key="ListBorder" Color="#828790"/>
        <Style x:Key="ListBoxStyleNoScrollViewer" TargetType="{x:Type ListBox}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
                            <!--<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">-->
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <!--</ScrollViewer>-->
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="true">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <ScrollViewer>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="200"/>
                <RowDefinition Height="100"/>
                <RowDefinition Height="200"/>
            </Grid.RowDefinitions>

            <ListBox Grid.Row="1" Style="{StaticResource ListBoxStyleNoScrollViewer}" >
                <ListBox.Items>
                    <ListBoxItem>One</ListBoxItem>
                    <ListBoxItem>Two</ListBoxItem>
                    <ListBoxItem>Three</ListBoxItem>
                    <ListBoxItem>Four</ListBoxItem>
                </ListBox.Items>
            </ListBox>
        </Grid>
    </ScrollViewer>
</Window>

リストボックスにある場合は、リストボックスStyle="{StaticResource ListBoxStyleNoScrollViewer}"の上にあるときにスクロールホイールが機能します。そうでない場合、サンプルはあなたが言及した問題を示しています。

于 2012-04-25T10:21:53.963 に答える
0

ListBox問題は、などの背景を透明に設定していることだと思いますBorder。これにより、マウスイベントだけでなくフォーカスも受け取れなくなります。色を付けますListBoxが、RGBAのA部分を反転します。たとえば次の例を試してください:#000A0A09(A = 0%の黒で、透明に見えます)

于 2012-04-20T16:35:07.800 に答える