Skip to content

Commit

Permalink
Displayed Header of Episode/Non-Episode Lists to allow resizing. Added
Browse files Browse the repository at this point in the history
ConverterMagic so that the last columns always takes all available space.
This closes #32.
  • Loading branch information
Dreamcooled committed Jul 19, 2015
1 parent 443bc64 commit 379aa34
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
23 changes: 14 additions & 9 deletions SjUpdater/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</controls:MetroWindow.RightWindowCommands>
<controls:MetroWindow.Resources>
<utils:StringToFaviconConverter x:Key="StringToFaviconConverter" />
<utils:GridViewWidthCalulationMultiConverter x:Key="lastColumnMaximizerConverter"/>
</controls:MetroWindow.Resources>
<controls:MetroWindow.Flyouts>
<controls:FlyoutsControl>
Expand Down Expand Up @@ -713,14 +714,9 @@


<ListView Grid.Row="5" Margin="10,0,10,10" ItemsSource="{Binding ListedDownloads}" x:Name="EpisodeFavorizedUploadsListView" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Links (Copy2Clipboard)">
<GridViewColumn Header="Links">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Links}">
Expand Down Expand Up @@ -750,12 +746,21 @@
</GridViewColumn>
<GridViewColumn Header="Format" DisplayMemberBinding="{Binding Upload.Format}" />
<GridViewColumn Header="Uploader" DisplayMemberBinding="{Binding Upload.Uploader}" />
<GridViewColumn Header="Size" DisplayMemberBinding="{Binding Upload.Size}" />
<GridViewColumn Header="Size" DisplayMemberBinding="{Binding Upload.Size}">
<GridViewColumn.Width>
<MultiBinding Converter="{StaticResource lastColumnMaximizerConverter}">
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource AncestorType=ListView}"/>
<Binding Path="View.Columns"
RelativeSource="{RelativeSource AncestorType=ListView}"/>
</MultiBinding>
</GridViewColumn.Width>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<TextBlock Grid.Row="5" Margin="15,5" Text="No Favorized Uploads yet." x:Name="EpisodeFavorizedWarning1" Foreground="{DynamicResource DisabledMenuItemForeground}" FontWeight="Bold" FontSize="13" Visibility="{Binding ShowNoFavUploadsWarning}"/>
<TextBlock Grid.Row="5" Margin="15,5" Text="Check here^^" x:Name="EpisodeFavorizedWarning2" HorizontalAlignment="Right" Foreground="{DynamicResource DisabledMenuItemForeground}" FontWeight="Bold" FontSize="13" Visibility="{Binding ShowNoFavUploadsWarning}"/>
<TextBlock Grid.Row="5" Margin="15,20,15,5" Text="No Favorized Uploads yet." x:Name="EpisodeFavorizedWarning1" Foreground="{DynamicResource DisabledMenuItemForeground}" FontWeight="Bold" FontSize="13" Visibility="{Binding ShowNoFavUploadsWarning}"/>
<TextBlock Grid.Row="5" Margin="15,20,15,5" Text="Check here^^" x:Name="EpisodeFavorizedWarning2" HorizontalAlignment="Right" Foreground="{DynamicResource DisabledMenuItemForeground}" FontWeight="Bold" FontSize="13" Visibility="{Binding ShowNoFavUploadsWarning}"/>

</Grid>

Expand Down
1 change: 1 addition & 0 deletions SjUpdater/SjUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Compile Include="Utils\FavIcon.cs" />
<Compile Include="Utils\GlobalMutex.cs" />
<Compile Include="Utils\GridViewColumnVisibilityManager.cs" />
<Compile Include="Utils\GridViewWidthCalulationMultiConverter.cs" />
<Compile Include="Utils\Native.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Settings.cs" />
Expand Down
16 changes: 10 additions & 6 deletions SjUpdater/SpecialDownloadList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<utils:StringToFaviconConverter x:Key="StringToFaviconConverter" />
<utils:GridViewWidthCalulationMultiConverter x:Key="lastColumnMaximizerConverter"/>
</UserControl.Resources>
<ListView ItemsSource="{Binding Path=ItemsSource, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:SpecialDownloadList}}}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Links (Copy2Clipboard)">
<GridViewColumn Header="Links">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding Links}">
Expand Down Expand Up @@ -54,6 +50,14 @@
<TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Title}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
<GridViewColumn.Width>
<MultiBinding Converter="{StaticResource lastColumnMaximizerConverter}">
<Binding Path="ActualWidth"
RelativeSource="{RelativeSource AncestorType=ListView}"/>
<Binding Path="View.Columns"
RelativeSource="{RelativeSource AncestorType=ListView}"/>
</MultiBinding>
</GridViewColumn.Width>
</GridViewColumn>
</GridView>
</ListView.View>
Expand Down
40 changes: 40 additions & 0 deletions SjUpdater/Utils/GridViewWidthCalulationMultiConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;

//Code taken from: http://stackoverflow.com/questions/5573152/how-to-resize-a-certain-control-based-on-window-size-in-wpf#5573895

namespace SjUpdater.Utils
{
public class GridViewWidthCalulationMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, CultureInfo culture)
{
// do some sort of calculation
double totalWindowWidth;
double otherColumnsTotalWidth = 0;
double.TryParse(values[0].ToString(), out totalWindowWidth);
var arrayOfColumns = values[1] as IList<GridViewColumn>;

for (int i = 0; i < arrayOfColumns.Count - 1; i++)
{
otherColumnsTotalWidth += arrayOfColumns[i].ActualWidth;
}

return (totalWindowWidth - otherColumnsTotalWidth) < 0 ?
0 : (totalWindowWidth - otherColumnsTotalWidth);
}

public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

0 comments on commit 379aa34

Please sign in to comment.