Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Sizing images inside grid and listbox
    primarykey
    data
    text
    <p>I have a ListBox with horizontal scrolling, and each item consists of a two row grid. The first row contains an image, and the second row a border used to render a reflection of the first.<br> (Yeah, yeah. I know. Yet another coverflow attempt...)</p> <p>I need some help with the sizing of the images. If I don't specify any size, it will render the image at full size, but I want it to be restricted by height of the grid row. If the window resizes, the images should resize.</p> <p>Any clues?</p> <p><strong>Update:</strong><br> I have now changed the code a little. First of all I have removed a unnecessary trigger, but the important part is </p> <ul> <li>Disabled vertical scrollbar on listbox. </li> <li>Removed height on coverImage</li> <li>Changed from layoutTransformation to RenderTransformation</li> <li>Shrink non-selected item instead of scaling selected item.</li> </ul> <p>This gives me nearly what I want. There is a gap between the coverImage and the coverReflection that I cant find a reason for. Any clues for that, og maybe I should post a new question...?</p> <p><strong>Second Update:</strong><br> I think I have a solution for the reflection-gap to now. It feels a little awkward, though. I guess there are better ways of doing it.</p> <p>What I've done is - I'm no longer flipping the border, I'm flipping the visual brush instead. - I have added a TileMode="Tile" for the visual brush</p> <p>Now, I'm not sure why this works, but it's coming close to what I want, so...</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="UntitledProject1.Window1" x:Name="Window" Title="Window1" Width="801" Height="786"&gt; &lt;Window.Resources&gt; &lt;XmlDataProvider x:Key="dataProvider" XPath="Bilder"&gt; &lt;x:XData&gt; &lt;Bilder xmlns=""&gt; &lt;Bilde&gt;75760-1_-8589666289339775808.jpg&lt;/Bilde&gt; &lt;Bilde&gt;73255-3_-8589662994232744558.jpg&lt;/Bilde&gt; &lt;Bilde&gt;75760-1_-8589666289339775808.jpg&lt;/Bilde&gt; &lt;Bilde&gt;73255-3_-8589662994232744558.jpg&lt;/Bilde&gt; &lt;Bilde&gt;75760-1_-8589666289339775808.jpg&lt;/Bilde&gt; &lt;Bilde&gt;73255-3_-8589662994232744558.jpg&lt;/Bilde&gt; &lt;/Bilder&gt; &lt;/x:XData&gt; &lt;/XmlDataProvider&gt; &lt;ControlTemplate x:Key="listControlTemplate" TargetType="{x:Type ListBoxItem}"&gt; &lt;Grid x:Name="listItemGrid"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition/&gt; &lt;RowDefinition/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Image x:Name="coverImage" Source="{Binding Path=InnerText}" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Grid.Row="0" RenderTransformOrigin="0.5,1"&gt; &lt;Image.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform ScaleX="0.7" ScaleY="0.7"/&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;RotateTransform Angle="0"/&gt; &lt;TranslateTransform X="0" Y="0"/&gt; &lt;/TransformGroup&gt; &lt;/Image.RenderTransform&gt; &lt;/Image&gt; &lt;Border x:Name="coverReflection" RenderTransformOrigin="0.5,0" Height="{Binding Path=ActualHeight, ElementName=coverImage, Mode= Default}" VerticalAlignment="Top" Grid.Row="1" &gt; &lt;Border.OpacityMask&gt; &lt;LinearGradientBrush EndPoint="0.0,1" StartPoint="0.0,0"&gt; &lt;GradientStop Color="#00000000" Offset="0.6"/&gt; &lt;GradientStop Color="#BBFFFFFF" Offset="0"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.OpacityMask&gt; &lt;Border.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform ScaleX="0.7" ScaleY="0.7"/&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;RotateTransform Angle="0"/&gt; &lt;TranslateTransform X="0" Y="0"/&gt; &lt;/TransformGroup&gt; &lt;/Border.RenderTransform&gt; &lt;Border.Background&gt; &lt;VisualBrush Visual="{Binding ElementName=coverImage}" TileMode="Tile"&gt; &lt;VisualBrush.Transform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform ScaleX="1" ScaleY="-1"/&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;RotateTransform Angle="0"/&gt; &lt;TranslateTransform X="0" Y="0"/&gt; &lt;/TransformGroup&gt; &lt;/VisualBrush.Transform&gt; &lt;/VisualBrush&gt; &lt;/Border.Background&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsSelected" Value="True"&gt; &lt;Setter Property="RenderTransform" TargetName="coverImage"&gt; &lt;Setter.Value&gt; &lt;TransformGroup&gt; &lt;ScaleTransform ScaleX="1" ScaleY="1"/&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;RotateTransform Angle="0"/&gt; &lt;TranslateTransform X="0" Y="0"/&gt; &lt;/TransformGroup&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="RenderTransform" TargetName="coverReflection"&gt; &lt;Setter.Value&gt; &lt;TransformGroup&gt; &lt;ScaleTransform ScaleX="1" ScaleY="1"/&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;RotateTransform Angle="0"/&gt; &lt;TranslateTransform X="0" Y="0"/&gt; &lt;/TransformGroup&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;Style TargetType="{x:Type ListBoxItem}" x:Key="listStyle"&gt; &lt;Setter Property="Template" Value="{StaticResource listControlTemplate}" /&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Window.BindingGroup&gt; &lt;BindingGroup/&gt; &lt;/Window.BindingGroup&gt; &lt;Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource dataProvider}, XPath=/Bilder/Bilde}"&gt; &lt;ListBox ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding }" IsSynchronizedWithCurrentItem="True" Background="#FF000000" ItemContainerStyle="{StaticResource listStyle}" VerticalAlignment="Stretch" &gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload