1
假设我有我的资源字典中类似这样的Image对象:如何使用资源对象使用XAML在面板的孩子吗?
<Image x:Key="Theme_Icon_Microphone" Source="Images/icon_microphone.png"/>
我想使用这个对象在DockPanel中
<DockPanel>
<!-- My Image object -->
</DockPanel>
假设我有我的资源字典中类似这样的Image对象:如何使用资源对象使用XAML在面板的孩子吗?
<Image x:Key="Theme_Icon_Microphone" Source="Images/icon_microphone.png"/>
我想使用这个对象在DockPanel中
<DockPanel>
<!-- My Image object -->
</DockPanel>
不要使用Image
作为静态的资源,因为你会只能使用一次。反而把BitmapImage
的资源和参考,从您的Image
:
<Grid>
<Grid.Resources>
<BitmapImage UriSource="http://thecybershadow.net/misc/stackoverflow.png" x:Key="image"/>
</Grid.Resources>
<DockPanel>
<Image Source="{StaticResource image}"/>
</DockPanel>
</Grid>