Skip to content

Commit

Permalink
Merge pull request #664 from punker76/fix/GH-356
Browse files Browse the repository at this point in the history
(GH-356) Improve Package view
  • Loading branch information
gep13 authored Apr 26, 2019
2 parents 2cb89c5 + e1a23d2 commit 4e04461
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 50 deletions.
1 change: 1 addition & 0 deletions Source/ChocolateyGui/ChocolateyGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
<Compile Include="Models\Messages\AboutGoBackMessage.cs" />
<Compile Include="Models\Messages\ShowAboutMessage.cs" />
<Compile Include="Utilities\BindingProxy.cs" />
<Compile Include="Utilities\BubbleScrollEventBehavior.cs" />
<Compile Include="Utilities\Converters\BooleanToVisibilityInverted.cs" />
<Compile Include="Utilities\Converters\NullToValue.cs" />
<Compile Include="Utilities\PackageAuthorsComparer.cs" />
Expand Down
12 changes: 8 additions & 4 deletions Source/ChocolateyGui/Resources/Controls.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,19 @@
</Style>

<Style x:Key="SectionHeaderStyle" BasedOn="{StaticResource MahApps.Metro.Styles.MetroHeader}" TargetType="{x:Type Controls:MetroHeader}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="28" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Foreground" Value="{StaticResource BodyColorBrush}" />
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="18" />
<Setter Property="Padding" Value="10 5 10 5"></Setter>
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="28" />
<Setter Property="Padding" Value="2 4" />
<Setter Property="Margin" Value="0 0 0 8" />
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Vertical" UseLayoutRounding="True">
<TextBlock Margin="0 10 0 5" Text="{Binding}" />
<Separator Margin="0 0 5 0"/>
<TextBlock Margin="0 0 0 4" Text="{Binding}" />
<Separator Margin="0 0 4 0"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
Expand Down
49 changes: 49 additions & 0 deletions Source/ChocolateyGui/Utilities/BubbleScrollEventBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Chocolatey" file="BubbleScrollEventBehavior.cs">
// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace ChocolateyGui.Utilities
{
/// <summary>
/// The BubbleScrollEventBehavior behavior can be used to prevent the mousewheel scrolling on a scrollable control.
/// The event will be bubble up to the parent control.
/// This behavior can be prevent with the left Shift key.
/// </summary>
public class BubbleScrollEventBehavior : Behavior<UIElement>
{
protected override void OnAttached()
{
base.OnAttached();

AssociatedObject.PreviewMouseWheel -= AssociatedObject_PreviewMouseWheel;
AssociatedObject.PreviewMouseWheel += AssociatedObject_PreviewMouseWheel;
}

protected override void OnDetaching()
{
AssociatedObject.PreviewMouseWheel -= AssociatedObject_PreviewMouseWheel;

base.OnDetaching();
}

private static void AssociatedObject_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
var uiElement = sender as UIElement;
if (uiElement == null || Keyboard.IsKeyDown(Key.LeftShift))
{
return;
}

e.Handled = true;

var e2 = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) { RoutedEvent = UIElement.MouseWheelEvent };
uiElement.RaiseEvent(e2);
}
}
}
92 changes: 46 additions & 46 deletions Source/ChocolateyGui/Views/PackageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
xmlns:lang="clr-namespace:ChocolateyGui.Properties"
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:utilities="clr-namespace:ChocolateyGui.Utilities"
mc:Ignorable="d"
d:DesignHeight="786" d:DesignWidth="1366"
d:DataContext="{d:DesignInstance viewModels:PackageViewModel}">
Expand Down Expand Up @@ -136,6 +138,18 @@
</Grid>

<StackPanel DockPanel.Dock="Left" Margin="20,0,0,0">
<controls:InternetImage AutomationProperties.Name="Package Icon"
IconUrl="{Binding IconUrl, IsAsync=True}"
Width="100" Height="100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="10" />
<Label Style="{StaticResource PackageResourceLabel}" Content="{x:Static lang:Resources.PackageView_PackageID}"
Visibility="{Binding Id, Converter={StaticResource NullToVisibility}}"
Target="{Binding ElementName=Id}" />
<TextBlock x:Name="Id" Text="{Binding Id}"
Visibility="{Binding Id, Converter={StaticResource NullToVisibility}}"
Style="{StaticResource PackageResourceValue}" />
<Label Style="{StaticResource PackageResourceLabel}" Content="{x:Static lang:Resources.PackageView_Version}"
Target="{Binding ElementName=Version}" />
<TextBlock x:Name="Version" Text="{Binding Version}"
Expand Down Expand Up @@ -192,52 +206,38 @@

</StackPanel>

<Grid DockPanel.Dock="Right">
<controls:InternetImage AutomationProperties.Name="Package Icon" IconUrl="{Binding IconUrl, IsAsync=True}"
Width="100" Height="100" HorizontalAlignment="Center" VerticalAlignment="Top"
Margin="0,0,20,0" />
</Grid>
<ScrollViewer Margin="25,5,0,0">
<StackPanel>
<mah:MetroHeader Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_Description}">
<i:Interaction.Behaviors>
<utilities:BubbleScrollEventBehavior />
</i:Interaction.Behaviors>
<markdig:MarkdownViewer AutomationProperties.Name="Package Description"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Markdown="{Binding Description}" />
</mah:MetroHeader>

<Grid Margin="25,5,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="5*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="{Binding ReleaseNotes, Converter={StaticResource NullToGridLength}}" />
</Grid.RowDefinitions>
<mah:MetroHeader Grid.Row="0"
Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_PackageID}"
Visibility="{Binding Id, Converter={StaticResource NullToVisibility}}">
<TextBlock Text="{Binding Id}"
TextWrapping="Wrap"
Style="{StaticResource PageTextBlockStyle}" />
</mah:MetroHeader>
<mah:MetroHeader Grid.Row="1"
Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_Description}">
<markdig:MarkdownViewer AutomationProperties.Name="Package Description"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Markdown="{Binding Description}" />
</mah:MetroHeader>
<mah:MetroHeader Grid.Row="2"
Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_Dependencies}"
Visibility="{Binding Dependencies, Converter={StaticResource NullToVisibility}}">
<TextBlock Text="{Binding Dependencies, Converter={StaticResource PackageDependenciesToString}}"
Style="{StaticResource PageTextBlockStyle}"
AutomationProperties.Name="Package Dependencies" />
</mah:MetroHeader>
<mah:MetroHeader Grid.Row="3"
Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_ReleaseNotes}"
Visibility="{Binding ReleaseNotes, Converter={StaticResource NullToVisibility}}">
<markdig:MarkdownViewer AutomationProperties.Name="Package Release Notes"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Markdown="{Binding ReleaseNotes}" />
</mah:MetroHeader>
</Grid>
<mah:MetroHeader Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_Dependencies}"
Visibility="{Binding Dependencies, Converter={StaticResource NullToVisibility}}">
<TextBlock Text="{Binding Dependencies, Converter={StaticResource PackageDependenciesToString}}"
AutomationProperties.Name="Package Dependencies" />
</mah:MetroHeader>

<mah:MetroHeader Style="{StaticResource SectionHeaderStyle}"
Header="{x:Static lang:Resources.PackageView_ReleaseNotes}"
Visibility="{Binding ReleaseNotes, Converter={StaticResource NullToVisibility}}">
<i:Interaction.Behaviors>
<utilities:BubbleScrollEventBehavior />
</i:Interaction.Behaviors>
<markdig:MarkdownViewer AutomationProperties.Name="Package Release Notes"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Markdown="{Binding ReleaseNotes}" />
</mah:MetroHeader>
</StackPanel>
</ScrollViewer>
</DockPanel>
</UserControl>
Expand Down

0 comments on commit 4e04461

Please sign in to comment.