Question

What I am trying to do is use the Imagebox as source for my bitmap effect and i dont know how to do that.My imagebox is called image1 .

<Button Content="Blur" Height="23" HorizontalAlignment="Left" Margin="148,12,0,0"    Name="button3" VerticalAlignment="Top" Width="42" Click="button3_Click" >
        <Image Source ="image1">
        <Image.BitmapEffect>
        <BlurBitmapEffect Radius="5" />
        </Image.BitmapEffect>
        </Image>
    </Button>
Was it helpful?

Solution

Are you using MVVM? If not, I highly recommend using this pattern because WPF is built to use it and if you don't, you will fight it all the way.

Create a ViewModel class. Create a public property of type Image in this ViewModel class.

Create an instace of the ViewModel and put it into your Window's datacontext. Then add a binding to this property.

Alternatively for a quick fix (please note that this leads to darkness, you will regret having started to program this way):

<Image Source="{Binding Source, ElementName=image1}"> 

Edit:

Your edit is a completely different story: You have set the Content property twice: once by directly setting it and once by having a child object. Your button has both a text and an image as content. But a button (and most other controls) can only have one content. If you want both, your content needs to be a container control like a StackPanel that can have multiple contents and you need to put both your Image and your TextBlock in there.

Example (you need to put in Orientation and Alignment as you see fit):

<Button Height="23" HorizontalAlignment="Left" Margin="148,12,0,0" Name="button3" VerticalAlignment="Top" Width="42" Click="button3_Click"> 
  <StackPanel>
    <TextBlock Text="Test"/>
    <Image Source="{Binding Source, ElementName=image1}">
      <Image.BitmapEffect>
        <BlurBitmapEffect Radius="5" />
      </Image.BitmapEffect>
    </Image>
</Button>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top