2

I'm creating a wpf application and implementing usb webcam to my Project using aforge. In my CameraWindow I have an Image control where I'm displaying lastest captured image from my usb webcam. Here is the sample

In my thirt window (AllCapturedImages) I have an Image control and in it I'm displaying latest captured image from usb webcam. This happens using Action() in my CameraWindow.

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

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

In the same window (AllCapturedImages) I have three more Image controls Here is one of them:

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

and what I want is change/update these Image's Source every time I capture an image.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

If you define the Button's ControlTemplate like this:

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

...you could simply set its Content property to an Image element:

var bitmapImage = CapturedImages.Last();
PreviewButton1.Content = new Image() { Source = bitmapImage };
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thanks for the answer! `` this is my `Image` control where I'm able to display lastest captured image right now. I have tested your answer to my second `Image` control but it is not diplaying anything :/ –  Apr 24 '17 at 10:53
  • What if you temporarilt try to set the Content of the Button to a TextBlock?: PreviewButton1.Content = new TextBlock() { Text = "TEST" }; Do you see the text? – mm8 Apr 24 '17 at 10:55
  • Nothing happens. I mean I dont see the text –  Apr 24 '17 at 10:57
  • What if you remove the part altogether. Do you even see the Button? – mm8 Apr 24 '17 at 11:09
  • Yes I see the button when I removed `` and it started working! :D I mean `PreviewButton1.Content = new Image() { Source = newImage };` I can see the latest captured image in my second `Image` control wtf... –  Apr 24 '17 at 11:24
  • You need to set the TargetType property of the ControlTemplate. I edited my answer. – mm8 Apr 24 '17 at 12:06