2017-04-24 19 views
2

私はwpfアプリケーションを作成し、aforgeを使用してusb webcamをプロジェクトに実装しています。私のCameraWindowに私はImageのコントロールを持っています。私のUSBウェブカメラからの最新のキャプチャ画像を表示しています。私thirtウィンドウ(AllCapturedImages)でHere is the sampleWPF - ボタンの画像をプログラム的に変更する方法

私はImageコントロールを持っていると それで私は、USBウェブカメラから最新の撮影した画像を表示しています。これは私のCameraWindowAction()を使っています。同じウィンドウ(AllCapturedImages)で

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

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

私はここでさらに3つのImageコントロール を持っているそのうちの一つである:

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

と私が欲しいの変更/更新これらImage年代Sourceは毎回ある私は、画像をキャプチャします。 お困りですか?

答えて

0

あなたはこのようButtonControlTemplateを定義する場合:

<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'コントロールです。私は2番目の 'Image'コントロールに対する答えをテストしましたが、何も表示していません:/ –

+0

一時的にボタンの内容をTextBlockに設定しようとするとどうなりますか?:PreviewButton1.Content = new TextBlock(){Text =" TEST "};テキストが見えますか? – mm8

+0

何も起こりません。テキストが表示されません。 –

関連する問題