2017-04-24 2 views
2

나는 aforge를 사용하여 wpf 응용 프로그램을 만들고 usb 웹캠을 내 프로젝트에 구현하고 있습니다. 내 CameraWindow에서 내컨트롤을 어디에 내 USB 웹캠에서 가장 최근에 캡처 한 이미지를 표시하고 있습니다. 내 thirt 창 (AllCapturedImages)에서 Here is the sample WPF - 버튼의 이미지를 프로그래밍 방식으로 변경하는 방법

가 나는 Image 제어 할 수 있으며 에서 나는의 USB 웹캠에서 최신 캡처 한 이미지를 표시하고 있습니다. 내 CameraWindowAction()을 사용하는이 hapens. 같은 창에서

<Image x:Name="newlyAddedImage" Margin="10,10,230,10"/> 

public Action<BitmapImage> newlyCapturedImage; 
if (newlyCapturedImage != null) 
{ 
    newlyCapturedImage(CapturedImages.Last()); 
} 

(AllCapturedImages) 나는 3 개 Image 컨트롤 여기 그들 중 하나가 :

<Button x:Name="PreviewButton1" Margin="577,10,25,404"> 
    <Button.Template> 
     <ControlTemplate> 
      <Image x:Name="SPPreviewImage1"></Image> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 

무엇을 내가 원하는 변화 /이 ImageSource마다 업데이트입니다 I 이미지를 캡처하십시오. 어떤 도움이 필요합니까?

답변

0

당신이 Button의이 같은 ControlTemplate을 정의하는 경우 :

<Button x:Name="PreviewButton1" Margin="577,10,25,404"> 
    <Button.Template> 
     <ControlTemplate TargetType="Button"> 
      <ContentPresenter /> 
     </ControlTemplate> 
    </Button.Template> 
</Button> 

... 당신이 단순히 Image 요소의 Content 속성을 설정할 수 있습니다 : 응답에 대한

var bitmapImage = CapturedImages.Last(); 
PreviewButton1.Content = new Image() { Source = bitmapImage }; 
+0

감사합니다! 'Image x : Name = "newlyAddedImage"Margin = "10,10,230,10"/> 이것은 현재 가장 최근 캡처 된 이미지를 표시 할 수있는 내 Image 컨트롤입니다. 두 번째 Image 컨트롤에 대한 답을 테스트했지만 아무것도 표시하지 않았습니다 :/ –

+0

임시 텍스트를 사용하여 Button의 내용을 TextBlock로 설정하려고하면 어떻게합니까? : PreviewButton1.Content = new TextBlock() {Text = " 테스트" }; 텍스트를 보시겠습니까? – mm8

+0

아무 반응이 없습니다. 텍스트가 보이지 않는다는 의미입니다. –

관련 문제