我在XAML中有两个几乎相同的图形用户界面结构,不同之处在于一个StackPanel在各自的结构中有一个图像和一个矩形,StackPanel也包含其他内容。我想只写一次孔结构,并有一个动态资源,其中一个放置的图像或矩形。代码将基本类似于:
<Style x:Key="myGrid" TargetType="{x:Type Grid}">
<!-- Many nested controls -->
<StackPanel>
<!-- Some differnt Controls -->
<Object Value="{DynamicResource someDynamicItem}" />
<StackPanel/>
</Style>
<Style x:Key="myGridWithImage" BasedOn="{StaticResource myGrid}" TargetType="{x:Type Grid}">
<Style.Resources>
<Image x:Key="someDynamicItem" />
</Style.Resources>
</Style>
<Style x:Key="myGridWithRectangle" BasedOn="{StaticResource myGrid}" TargetType="{x:Type Grid}">
<Style.Resources>
<Rectangle x:Key="someDynamicItem" />
</Style.Resources>
</Style>有没有可能有任何类型的占位符(而不是Object-Tag)可以通过这种方式动态分配?
发布于 2015-04-08 16:35:25
我建议在你的情况下,内容控制优于堆栈面板,这样将来如果你需要适应其他东西,你只需要在内容控制中提供一个新的内容。
https://stackoverflow.com/questions/29509666
复制相似问题