This commit is contained in:
bao-qian 2016-05-23 01:25:52 +01:00
parent 95cdc89795
commit e480cdbf9b
2 changed files with 15 additions and 26 deletions

View File

@ -6,12 +6,12 @@
xmlns:vm="clr-namespace:Wox.ViewModel" xmlns:vm="clr-namespace:Wox.ViewModel"
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100" mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"
d:DataContext="{d:DesignInstance vm:ResultsViewModel}" d:DataContext="{d:DesignInstance vm:ResultsViewModel}"
MaxHeight="{Binding MaxHeight}" MaxHeight="{Binding MaxHeight}"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}"
HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Results}"
Margin="{Binding Margin}" Margin="{Binding Margin}"
Style="{DynamicResource BaseListboxStyle}" Focusable="False" Style="{DynamicResource BaseListboxStyle}" Focusable="False"
KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"
SelectionChanged="OnSelectionChanged" SelectionChanged="OnSelectionChanged"
@ -26,7 +26,7 @@
</ControlTemplate> </ControlTemplate>
</Button.Template> </Button.Template>
<Button.Content> <Button.Content>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5"
Cursor="Hand" UseLayoutRounding="False"> Cursor="Hand" UseLayoutRounding="False">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="32" /> <ColumnDefinition Width="32" />
@ -41,22 +41,21 @@
<RowDefinition Height="Auto" x:Name="SubTitleRowDefinition" /> <RowDefinition Height="Auto" x:Name="SubTitleRowDefinition" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Style="{DynamicResource ItemTitleStyle}" DockPanel.Dock="Left" <TextBlock Style="{DynamicResource ItemTitleStyle}" DockPanel.Dock="Left"
VerticalAlignment="Center" ToolTip="{Binding Title}" x:Name="tbTitle" VerticalAlignment="Center" ToolTip="{Binding Title}" x:Name="Title"
Text="{Binding Title}" /> Text="{Binding Title}" />
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding SubTitle}" <TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding SubTitle}"
Grid.Row="1" x:Name="tbSubTitle" Text="{Binding SubTitle}" /> Grid.Row="1" x:Name="SubTitle" Text="{Binding SubTitle}" />
</Grid> </Grid>
</Grid> </Grid>
</Button.Content> </Button.Content>
</Button> </Button>
<!-- a result item height is 50 including margin --> <!-- a result item height is 50 including margin -->
<DataTemplate.Triggers> <DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected}" Value="True"> <DataTrigger
<Setter TargetName="tbTitle" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}" /> Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"
</DataTrigger> Value="True">
<DataTrigger Binding="{Binding Path=IsSelected}" Value="True"> <Setter TargetName="Title" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}" />
<Setter TargetName="tbSubTitle" Property="Style" <Setter TargetName="SubTitle" Property="Style" Value="{DynamicResource ItemSubTitleSelectedStyle}" />
Value="{DynamicResource ItemSubTitleSelectedStyle}" />
</DataTrigger> </DataTrigger>
</DataTemplate.Triggers> </DataTemplate.Triggers>
</DataTemplate> </DataTemplate>
@ -64,11 +63,11 @@
<!--http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062--> <!--http://stackoverflow.com/questions/16819577/setting-background-color-or-wpf-4-0-listbox-windows-8/#16820062-->
<ListBox.ItemContainerStyle> <ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}"> <Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseEnter" Handler="OnMouseEnter"></EventSetter> <EventSetter Event="MouseEnter" Handler="OnMouseEnter" />
<Setter Property="Height" Value="50" /> <Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="0" /> <Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0"/> <Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0" />
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}"> <ControlTemplate TargetType="{x:Type ListBoxItem}">

View File

@ -63,16 +63,6 @@ namespace Wox.ViewModel
set { RawResult.Action = value; } set { RawResult.Action = value; }
} }
public bool IsSelected
{
get { return _isSelected; }
set
{
_isSelected = value;
OnPropertyChanged();
}
}
#endregion #endregion
#region Properties #region Properties