WPF一个元素一个资源?

WPF一个元素一个资源?,wpf,Wpf,一个资源项是否同时只能用于一个元素? 例如: [xaml] <Window.Resources> <Image x:Key="DockImage" Source="ico/pin.gif"/> <Image x:Key="UndockImage" Source="ico/pinHorizontal.gif"/> </Window.Resources> 和按钮: <Button Width="26" Name="solut

一个资源项是否同时只能用于一个元素? 例如:

[xaml]

<Window.Resources>
    <Image x:Key="DockImage" Source="ico/pin.gif"/>
    <Image x:Key="UndockImage" Source="ico/pinHorizontal.gif"/>
</Window.Resources>

和按钮:

<Button Width="26" Name="solutionButton" Click="eventname">
       <DynamicResource ResourceKey="DockImage"/>
 </Button>
<Button Width="26" Name="soundButton" Click="eventname2">
       <DynamicResource ResourceKey="DockImage"/>
 </Button>

它们的图像在运行时更改为UndockImage,但图像仅显示在其中一个按钮上。
我可以为DockImage和UndockImage增加图像键,但我认为这将占用2倍的内存。一个资源密钥是否可以(同时)用于一个对象

UIElement
派生的任何内容一次只能在一个位置显示。您不应该直接定义
Image
资源,这是用于显示图像的控件。相反,使用一些
ImageSource
派生的类,例如
BitmapImage
,它表示内存中的图像

<Window.Resources>
  <BitmapImage x:Key="DockImage" UriSource="ico/pin.gif"/>
  <BitmapImage x:Key="UndockImage" UriSource="ico/pinHorizontal.gif"/>
</Window.Resources>

<Button Width="26" Name="solutionButton" Click="eventname">
  <Image Source="{StaticResource DockImage}"/>
</Button>
<Button Width="26" Name="soundButton" Click="eventname2">
  <Image Source="{StaticResource DockImage}"/>
</Button>

UIElement
派生的任何内容一次只能在一个位置显示。您不应该直接定义
Image
资源,这是用于显示图像的控件。相反,使用一些
ImageSource
派生的类,例如
BitmapImage
,它表示内存中的图像

<Window.Resources>
  <BitmapImage x:Key="DockImage" UriSource="ico/pin.gif"/>
  <BitmapImage x:Key="UndockImage" UriSource="ico/pinHorizontal.gif"/>
</Window.Resources>

<Button Width="26" Name="solutionButton" Click="eventname">
  <Image Source="{StaticResource DockImage}"/>
</Button>
<Button Width="26" Name="soundButton" Click="eventname2">
  <Image Source="{StaticResource DockImage}"/>
</Button>