Доброго времени суток,Уважаемые. Вопрос такой: Имеется ListView со своим стилем. При добавлении ListViewItem в окно View событие IsSelected отрабатывает верно, т.е. в фокусе тот элемент которые нужно. При Binding'e же Select'ится только первый элемент по триггеру и не "отлипает" при всякических уговорах). Binding пробовал организовать как на ObservableCollection<string> так и на CollectionViewSource,но видимо это только на некоторую производительность может влиять. СобсТвенно как выглядит ListView во View Код | <ListView Margin="10" Width="Auto" ItemsSource="{Binding Names,UpdateSourceTrigger=PropertyChanged}"> <ListView.View> <GridView AllowsColumnReorder="True"> <GridViewColumn DisplayMemberBinding="{Binding}" Header="Дата" Width="auto"/> <GridViewColumn DisplayMemberBinding="{Binding}" Header="Номер" Width="50"/> <GridViewColumn Header="Стадия" Width="75"> <GridViewColumn.CellTemplate> <DataTemplate> <Grid DataContext="{Binding}" HorizontalAlignment="Center" Height="50"> <TextBlock Text="{Binding}" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn DisplayMemberBinding="{Binding}" Header="Статус" Width="auto" /> <GridViewColumn DisplayMemberBinding="{Binding}" Header="Дата и время последней отправки на сервер" Width="auto" />
</GridView> </ListView.View>
<!--<i:Interaction.Triggers> <i:EventTrigger EventName="SourceUpdated"> <ei:CallMethodAction TargetObject="{Binding}" MethodName="Submit"/> </i:EventTrigger> </i:Interaction.Triggers>--> </ListView>
|
Стиль ListView c тригами Код | <Style TargetType="{x:Type ListView}"> <Setter Property="Background" Value="{StaticResource ControlLightBackground}" /> <Setter Property="BorderBrush" Value="{StaticResource ControlBorderBrush}" /> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Foreground" Value="{StaticResource ControlForegroundWhite}" /> <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="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListView}"> <Border x:Name="Bd" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"> <ScrollViewer Padding="{TemplateBinding Padding}" Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </ScrollViewer> </Border> <ControlTemplate.Triggers>
<Trigger Property="IsGrouping" Value="True"> <Setter Property="ScrollViewer.CanContentScroll" Value="False" /> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" TargetName="Bd" Value="{StaticResource DisabledBrush}" /> <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource DisabledBorderBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}"> <Setter Property="Focusable" Value="False" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Grid SnapsToDevicePixels="True" Background="{TemplateBinding Background}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <DockPanel Margin="{TemplateBinding Padding}"> <ScrollViewer Focusable="False" DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> <GridViewHeaderRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="2,0,2,0" AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" Columns="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}" /> </ScrollViewer> <ScrollContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ScrollContentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" CanContentScroll="{TemplateBinding CanContentScroll}" KeyboardNavigation.DirectionalNavigation="Local" /> </DockPanel> <ScrollBar Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Cursor="Arrow" x:Name="PART_HorizontalScrollBar" Grid.Row="1" Orientation="Horizontal" ViewportSize="{TemplateBinding ViewportWidth}" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0.0" Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" /> <ScrollBar Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Cursor="Arrow" x:Name="PART_VerticalScrollBar" Grid.Column="1" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0.0" Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" /> <DockPanel Grid.Column="1" Grid.Row="1" Background="{Binding Path=Background, ElementName=PART_VerticalScrollBar}" LastChildFill="False"> <Rectangle Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Width="1" Fill="White" DockPanel.Dock="Left" /> <Rectangle Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Height="1" Fill="White" DockPanel.Dock="Top" /> </DockPanel> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
|
Стиль ListViewItem'a Код | <Style TargetType="{x:Type ListViewItem}"> <Setter Property="FocusVisualStyle" Value="{DynamicResource ListViewItemFocusVisual}" /> <Setter Property="Background" Value="Transparent" /> <Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="Foreground" Value="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListView}}}"/> <Setter Property="BorderThickness" Value="1" /> <Setter Property="Margin" Value="0,0,0,1" /> <Setter Property="Padding" Value="5,2" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <ControlTemplate.Resources> <Storyboard x:Key="HoverOn"> <ColorAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="row_content" To="{StaticResource ColorForeground}"/> </Storyboard> <Storyboard x:Key="HoverOff"> <ColorAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="row_content" To="{StaticResource ColorForegroundWhite}"/> </Storyboard> <Storyboard x:Key="SelectedOn"> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HoverSelected" To="1"/> </Storyboard> <Storyboard x:Key="SelectedOff"> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HoverSelected" To="0"/> </Storyboard> </ControlTemplate.Resources> <Border SnapsToDevicePixels="True" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" x:Name="border"> <Grid Margin="2,0"> <Rectangle x:Name="Background" IsHitTestVisible="False" Fill="{TemplateBinding Background}" RadiusX="0" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}"/>
<Rectangle x:Name="HoverSelected" IsHitTestVisible="False" Opacity="0" RadiusX="0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="{StaticResource HighlightComboBoxItem1}"/> <GradientStop Offset="1" Color="{StaticResource HighlightComboBoxItem2}"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <Border Background="Transparent"> <GridViewRowPresenter x:Name="row_content" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Stretch" Margin="0,2" /> </Border> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="True"> <Trigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource SelectedOn}"/> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard Storyboard="{StaticResource SelectedOff}"/> </Trigger.ExitActions> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="Selector.IsSelected" Value="False" /> </MultiTrigger.Conditions> <MultiTrigger.EnterActions> <BeginStoryboard Storyboard="{StaticResource HoverOn}"/> </MultiTrigger.EnterActions> <MultiTrigger.ExitActions> <BeginStoryboard Storyboard="{StaticResource HoverOff}"/> </MultiTrigger.ExitActions> </MultiTrigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground"> <Setter.Value> <SolidColorBrush Color="{StaticResource DisabledForeground3}"/> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
|
Сам Байндинг проходит успешно. И Hover отрабатывает на TextBlock'e верно. Вопрос такой почему UIElement.Opacity ставится в соответствие первый элемент. Ведь каждый Item обернут в grid. Вопрос снимаю) Беда как раз была в баиндинге)) Я ссылку на один и тот же объект передавал. Будьте внимательны при работе с коллекциями) И я тоже буду внимателен)) Всем спасибо) Это сообщение отредактировал(а) qwerty123456 - 2.2.2013, 18:16
|