2011-10-19 4 views

답변

2

당신은 그럼 당신은 당신이 할 수있는 버튼을 클릭 이벤트 내부에 코드 숨김에서 XAML

<Button x:Name="button" Content="{StaticResource ResourceKey=MyImageSource}"></Button> 

이 같은 버튼에 이미지를 설정할 수 있습니다이

<Style TargetType="Button"> 
      <Setter Property="ContentTemplate"> 
       <Setter.Value> 
        <DataTemplate> 
         <StackPanel Orientation="Horizontal"> 
          <Image Width="16" Height="16" Stretch="UniformToFill" Source="{Binding}"/> 
         </StackPanel> 
        </DataTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

같은 button에 대한 DataTemplate을 작성해야 이렇게하면 런타임에 백그라운드를 바꿀 수 있습니다.

button.Content = YourImage; 
+0

죄송합니다 ew in xaml. xaml 코드는 어디에 붙여야합니까? – noDispName

+0

이 코드를 페이지의'resources' 섹션에 붙여 넣거나 시나리오에있는 것을 제어 할 수 있습니다. –