Correct height of row items

This commit is contained in:
Peter Kirmeier 2022-11-09 23:34:27 +01:00
parent 2a820d9099
commit 32e3813eb1
2 changed files with 15 additions and 8 deletions

View file

@ -9,7 +9,7 @@
xmlns:utils="clr-namespace:SystemTrayMenu.Utilities" xmlns:utils="clr-namespace:SystemTrayMenu.Utilities"
xmlns:local="clr-namespace:SystemTrayMenu.UserInterface" xmlns:local="clr-namespace:SystemTrayMenu.UserInterface"
x:Class="SystemTrayMenu.UserInterface.Menu" x:Class="SystemTrayMenu.UserInterface.Menu"
mc:Ignorable="d" ResizeMode="NoResize" WindowStyle="None" Topmost="True" Background="Transparent" AllowsTransparency="True" SizeToContent="WidthAndHeight" ShowInTaskbar="False"> mc:Ignorable="d" ResizeMode="NoResize" WindowStyle="None" Topmost="True" Background="Transparent" AllowsTransparency="True" SizeToContent="WidthAndHeight" ShowInTaskbar="False" SnapsToDevicePixels="True" UseLayoutRounding="True">
<Window.Effect> <Window.Effect>
<DropShadowEffect/> <DropShadowEffect/>
</Window.Effect> </Window.Effect>
@ -121,12 +121,12 @@
</Button> </Button>
</DockPanel> </DockPanel>
<ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="{x:Null}" Background="{x:Null}"> <ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="{x:Null}" Background="{x:Null}" SelectionMode="Single">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Height="{DynamicResource RowHeight}">
<Image Width="{DynamicResource ColumnIconWidth}" Source="{Binding ColumnIcon, Converter={utils:IconToImageSourceConverter}}"/> <Image Width="{DynamicResource ColumnIconWidth}" Margin="0,2,0,3" Source="{Binding ColumnIcon, Converter={utils:IconToImageSourceConverter}}" />
<Label Width="{DynamicResource ColumnTextWidth}" Margin="6,0" Padding="0" VerticalContentAlignment="Center"> <Label Width="{DynamicResource ColumnTextWidth}" Margin="3,0" Padding="0" VerticalContentAlignment="Center">
<TextBlock TextTrimming="CharacterEllipsis" Text="{Binding ColumnText}"/> <TextBlock TextTrimming="CharacterEllipsis" Text="{Binding ColumnText}"/>
</Label> </Label>
</StackPanel> </StackPanel>
@ -134,6 +134,9 @@
</ListView.ItemTemplate> </ListView.ItemTemplate>
<ListView.ItemContainerStyle> <ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
<EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" /> <EventSetter Event="MouseEnter" Handler="ListViewItem_MouseEnter" />
<EventSetter Event="MouseLeave" Handler="ListViewItem_MouseLeave" /> <EventSetter Event="MouseLeave" Handler="ListViewItem_MouseLeave" />
<EventSetter Event="PreviewMouseDown" Handler="ListViewItem_MouseDown" /> <EventSetter Event="PreviewMouseDown" Handler="ListViewItem_MouseDown" />

View file

@ -890,14 +890,14 @@ namespace SystemTrayMenu.UserInterface
// 175% = 33 instead 37, 200% = 35 instead 42 // 175% = 33 instead 37, 200% = 35 instead 42
// #418 use 21 as default and scale it manually // #418 use 21 as default and scale it manually
double rowHeightDefault = 21.24f * Scaling.FactorByDpi; double rowHeightDefault = 21.24f * Scaling.FactorByDpi;
Resources["RowHeight"] = (double)((rowHeightDefault * factor * Scaling.Factor) + 0.5); Resources["RowHeight"] = (double)(int)((rowHeightDefault * factor * Scaling.Factor) + 0.5);
dgv.Tag = true; dgv.Tag = true;
} }
} }
else else
{ {
// Take over the height from predecessor menu // Take over the height from predecessor menu
Resources["RowHeight"] = (double)menuPredecessor.Resources["RowHeight"]; Resources["RowHeight"] = (double)(int)menuPredecessor.Resources["RowHeight"];
dgv.Tag = true; dgv.Tag = true;
} }
@ -944,7 +944,7 @@ namespace SystemTrayMenu.UserInterface
double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f; double factorIconSizeInPercent = Properties.Settings.Default.IconSizeInPercent / 100f;
// IcoWidth 100% = 21px, 175% is 33, +3+2 is padding from ColumnIcon // IcoWidth 100% = 21px, 175% is 33, +3+2 is padding from ColumnIcon
double icoWidth = (16 * Scaling.FactorByDpi) + 5; double icoWidth = (16 * Scaling.FactorByDpi) + 5;
Resources["ColumnIconWidth"] = (double)((icoWidth * factorIconSizeInPercent * Scaling.Factor) + 0.5); Resources["ColumnIconWidth"] = (double)(int)((icoWidth * factorIconSizeInPercent * Scaling.Factor) + 0.5);
double renderedMaxWidth = 0D; double renderedMaxWidth = 0D;
foreach (ListViewItemData item in dgv.Items) foreach (ListViewItemData item in dgv.Items)
@ -1342,6 +1342,10 @@ namespace SystemTrayMenu.UserInterface
{ {
timerUpdateIcons.Stop(); timerUpdateIcons.Stop();
} }
else
{
((CollectionView)CollectionViewSource.GetDefaultView(dgv.ItemsSource)).Refresh();
}
} }
private void Menu_MouseDown(object sender, MouseButtonEventArgs e) private void Menu_MouseDown(object sender, MouseButtonEventArgs e)