admin管理员组文章数量:1316307
I'm trying to replicate a very simple CSS effect that zooms the background of a container on hover in Avalonia. For this, I'm using a Canvas and an Image, which allows the image to clip as intended, albeit from the top left corner, instead of the center of the canvas. I would like to have the image aligned in the center and stay aligned there, even during resizing. My setup looks something like this:
<ItemsRepeater>
<ItemsRepeater.ItemTemplate>
<Button>
<Canvas Width="300" Height="200" ClipToBounds="True">
<Image Source="{Binding Thumbnail}" Stretch="Uniform" />
</Canvas>
</Button>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
<Style Selector="ItemsRepeater Button Image">
<Setter Property="Width" Value="300"/>
</Style>
<Style Selector="ItemsRepeater Button:pointerover Image">
<Setter Property="Width" Value="320"/>
</Style>
Unfortunately naming the elements and setting the canvas top/left in the code-behind isn't an option as far as I'm aware due to the ItemsRepeater. Neither is iterating over the items, as Avalonia doesn't support something like ItemsRepeater.Items.
I'm honestly incredibly stumped, because something like this can be done in like two lines of CSS. Any help would be appreciated.
I'm trying to replicate a very simple CSS effect that zooms the background of a container on hover in Avalonia. For this, I'm using a Canvas and an Image, which allows the image to clip as intended, albeit from the top left corner, instead of the center of the canvas. I would like to have the image aligned in the center and stay aligned there, even during resizing. My setup looks something like this:
<ItemsRepeater>
<ItemsRepeater.ItemTemplate>
<Button>
<Canvas Width="300" Height="200" ClipToBounds="True">
<Image Source="{Binding Thumbnail}" Stretch="Uniform" />
</Canvas>
</Button>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
<Style Selector="ItemsRepeater Button Image">
<Setter Property="Width" Value="300"/>
</Style>
<Style Selector="ItemsRepeater Button:pointerover Image">
<Setter Property="Width" Value="320"/>
</Style>
Unfortunately naming the elements and setting the canvas top/left in the code-behind isn't an option as far as I'm aware due to the ItemsRepeater. Neither is iterating over the items, as Avalonia doesn't support something like ItemsRepeater.Items.
I'm honestly incredibly stumped, because something like this can be done in like two lines of CSS. Any help would be appreciated.
Share Improve this question asked Jan 29 at 10:12 SeiSei 131 silver badge2 bronze badges 01 Answer
Reset to default 1You may want to set the Image's RenderTransform
property:
<Style Selector="ItemsRepeater Button:pointerover Image">
<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.067" ScaleY="1.067"/>
</Setter.Value>
</Setter>
</Style>
<ItemsRepeater ItemsSource="{Binding Items}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Button>
<Image Width="300" Height="200" Source="{Binding Thumbnail}"/>
</Button>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</Grid>
本文标签: cAvalonia Center An Element Inside a Canvas Inside an ItemsRepeaterStack Overflow
版权声明:本文标题:c# - Avalonia Center An Element Inside a Canvas Inside an ItemsRepeater - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742004066a2411602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论