我有一个带有ResourceKey和Caption的List值,这些值都是字符串.资源是资源字典中定义的实际资源的名称.这些ResourceKey图标中的每一个都是Canvas的.
<Data ResourceKey="IconCalendar" Caption="Calendar"/>
<Data ResourceKey="IconEmail" Caption="Email"/>
Run Code Online (Sandbox Code Playgroud)
然后我有一个列表视图,其中有一个带按钮的datatemplate和按钮下方的文本标题.我想要做的是显示资源静态资源作为按钮的内容.
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Content="{Binding ResourceKey}" Template="{StaticResource RoundButtonControlTemplate}"/>
<TextBlock Grid.Row="1" Margin="0,10,0,0" Text="{Binding Caption}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
我想我已尝试使用绑定staticresource等进行每个排列.
我对替代方案持开放态度,我知道拥有一个图像并设置source属性可能更容易.
谢谢