Scrollviewer blocking events

 
0
 
.NET
ava
fakefreak | 30.06.2012, 11:18

internal class myRTB : System.Windows.Controls.RichTextBox{
internal bool editable = false;

public myRTB(){
this.MouseDown += new System.Windows.Input.MouseButtonEventHandler(myRTB_MouseDown);
}
void myRTB_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e){
int tmp333 = 333;
}
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e){
int tmp333 = 333;
}
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e){
int tmp333 = 333;
}
protected override void OnMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs e){
int tmp333 = 333;
}
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e){
int tmp333 = 333;
}
protected override void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e){
int tmp333 = 333;
}
}
//выставляю точки останова на событиях


--------------------------------------------------------------

//если сделать так, то ни одно из событий от мыши никогда ни в каком случае не проходит:
internal System.Windows.Controls.ScrollViewer scroll;
internal myRTB innerTextBox;
scroll = (System.Windows.Controls.ScrollViewer)System.Windows.Markup.XamlReader.Load(stream);
host.Child = scroll;
scroll.Content = innerTextBox;

--------------------------------------------------------------

//если же сделать так, то всё ок:
internal System.Windows.Controls.ScrollViewer scroll;
internal myRTB innerTextBox;
host.Child = innerTextBox;

--------------------------------------------------------------
т.е. ScrollViewer гасит все события, и они не доходят до контента. что делать? почему так?
Comments (2)
ava
fakefreak | 01.07.2012, 18:16 #
Обнаружил такую штуку:
если инициализировать ScrollViewer не через xaml код

scroll = (System.Windows.Controls.ScrollViewer)System.Windows.Markup.XamlReader.Load(stream);

, а инициализировать его конструктором по умолчанию

scroll = new System.Windows.Controls.ScrollViewer();

то события от мыши к контенту ScrollViewer'а проходят хорошо.
Xaml код у меня такой:

<ScrollViewer x:Class="DeskNotes.myScrollViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" xmlns:c="clr-namespace:DeskNotes" x:ClassModifier="public" MouseDown="ScrollViewer_MouseDown" MouseUp="ScrollViewer_MouseUp" MouseMove="ScrollViewer_MouseMove">
<ScrollViewer.Resources>
<Style x:Key="{x:Type myScrollViewer}" TargetType="{x:Type myScrollViewer}">
<Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
<Setter Property="VerticalScrollBarVisibility" Value="Hidden"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type myScrollViewer}">
<Grid>
<Grid Background="{TemplateBinding Background}">
<ScrollContentPresenter
x:Name="PART_ScrollContentPresenter"
Width="{TemplateBinding ActualWidth}"
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
CanContentScroll="{TemplateBinding CanContentScroll}"/>
</Grid>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollBar
x:Name="PART_VerticalScrollBar"
Grid.Column="1"
Minimum="0.0"
Maximum="{TemplateBinding ScrollableHeight}"
ViewportSize="{TemplateBinding ViewportHeight}"
Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=VerticalOffset, Mode=OneWay}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Cursor="Arrow"
AutomationProperties.AutomationId="VerticalScrollBar"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="ScrollBarButton" TargetType="{x:Type RepeatButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Path x:Name="Arrow" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{TemplateBinding Background}"/>
<ControlTemplate.Triggers>
<Trigger Property="theme:ScrollChrome.ScrollGlyph" Value="UpArrow">
<Setter TargetName="Arrow" Property="Data" Value="M 3,0 l 3,8 l -6,0 Z"/>
</Trigger>
<Trigger Property="theme:ScrollChrome.ScrollGlyph" Value="DownArrow">
<Setter TargetName="Arrow" Property="Data" Value="M 0,0 l 6,0 l -3,8 Z"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="#FF777777" CornerRadius="2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="VerticalScrollBarPageButton" TargetType="{x:Type RepeatButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Rectangle Fill="{TemplateBinding Background}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="Background" Value="#FF979797"/>
<Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Width" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<Setter Property="MinWidth" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Border
x:Name="Bg"
CornerRadius="2"
Margin="2"
Opacity="0.75"
Background="{TemplateBinding Background}"
VerticalAlignment="Bottom">
<Grid SnapsToDevicePixels="true">
<Grid.RowDefinitions>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
</Grid.RowDefinitions>
<RepeatButton
Style="{StaticResource ScrollBarButton}"
Background="#FFCBCBCB"
IsEnabled="{TemplateBinding IsMouseOver}"
Command="{x:Static ScrollBar.LineUpCommand}"
theme:ScrollChrome.ScrollGlyph="UpArrow"
Margin="0,4"/>
<RepeatButton
Style="{StaticResource ScrollBarButton}"
Background="#FFCBCBCB"
Grid.Row="1"
IsEnabled="{TemplateBinding IsMouseOver}"
Command="{x:Static ScrollBar.LineDownCommand}"
theme:ScrollChrome.ScrollGlyph="DownArrow"
Margin="0,4">
</RepeatButton>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Bg" Property="Visibility" Value="Hidden"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="Orientation" Value="Vertical"/>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="Width" Value="30"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Border
CornerRadius="4"
Margin="2"
Opacity="0.75"
Background="{TemplateBinding Background}">
<Grid SnapsToDevicePixels="true">
<Grid.RowDefinitions>
<RowDefinition Height="0.00001*"/>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
<RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
</Grid.RowDefinitions>
<Track Name="PART_Track" IsEnabled="{TemplateBinding IsMouseOver}" IsDirectionReversed="true">
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource VerticalScrollBarPageButton}" Command="{x:Static ScrollBar.PageUpCommand}"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource VerticalScrollBarPageButton}" Command="{x:Static ScrollBar.PageDownCommand}"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" theme:ScrollChrome.ScrollGlyph="VerticalGripper" Margin="2"/>
</Track.Thumb>
</Track>
<RepeatButton
Style="{StaticResource ScrollBarButton}"
Background="#FFFFFFFF"
Grid.Row="1"
IsEnabled="{TemplateBinding IsMouseOver}"
Command="{x:Static ScrollBar.LineUpCommand}"
theme:ScrollChrome.ScrollGlyph="UpArrow"
RenderTransformOrigin="0.5, 0.5">
<RepeatButton.RenderTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
</RepeatButton.RenderTransform>
</RepeatButton>
<RepeatButton
Style="{StaticResource ScrollBarButton}"
Background="#FFFFFFFF"
Grid.Row="2"
IsEnabled="{TemplateBinding IsMouseOver}"
Command="{x:Static ScrollBar.LineDownCommand}"
theme:ScrollChrome.ScrollGlyph="DownArrow"
RenderTransformOrigin="0.5, 0.5">
<RepeatButton.RenderTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5"/>
</RepeatButton.RenderTransform>
</RepeatButton>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
</ScrollViewer.Resources>
</ScrollViewer>

Соответственно, делаю вывод, что не пропускает события мыши к контенту именно ScrollContentPresenter.
Видимо не пропускает из-за того, что контент ScrollContentPresenter'а забинден к контенту ScrollViewer'а.
Что сделать, чтобы до контента всё-таки доходили события мыши?
ava
RastaDja | 02.07.2012, 12:01 #

private void ScrollViewer_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
}


Оно?
Please register or login to write.
Firm of day
Вы также можете добавить свою фирму в каталог IT-фирм, и публиковать статьи, новости, вакансии и другую информацию от имени фирмы.
Подробнее
Contributors
advanced
Submit