【发布时间】:2022-01-18 13:54:15
【问题描述】:
在 XAML 文件中,我将图像定义为资源。当然,我可以将它分配为 ContenControl 的内容(如按钮)。 XAML 中是否有办法将此类资源添加到面板的子项(如网格)
<!--Creation of the Image as a resource (in this case loaded from assembly ressources)-->
<ResourceDictionary>
<Image x:Key="CheckImage" x:Shared="False" Margin="0" Stretch="None" Source="/CheckStyleRes;component/CHECK.png" HorizontalAlignment="Center" VerticalAlignment="Center" IsHitTestVisible="True" SnapsToDevicePixels="True" UseLayoutRounding="True"/>
</ResourceDictionary>
...
<!--This is a workaround, putting the Image into an ContentControl and this into the Children-->
<Grid>
<Grid.Children>
<ContentControl x:Name="CheckMark" Content="{StaticResource CheckImage}"></ContentControl>
</Grid.Children>
</Grid>
...
<!--But is there a syntax to add {StaticResource CheckImage} directly to Grid.Children-->
<Grid>
<Grid.Children>
<Image FromRessourceOrSomthingLikeThat= "{StaticResource CheckImage}">
</Grid.Children>
</Grid>
我不想要 ImageSource 作为资源(然后我可以使用 Image 的 Source-Property 并在 Children 中创建图像)。我的资源应该是可以使用的图像。谢谢。
【问题讨论】: