0

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>

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

7 Comments

<Button Content="Blur" Height="23" HorizontalAlignment="Left" Margin="148,12,0,0" Name="button3" VerticalAlignment="Top" Width="42" Click="button3_Click" > <Image Source="{Binding Source, ElementName=image1}"> <Image.BitmapEffect> <BlurBitmapEffect Radius="5" /> </Image.BitmapEffect> </Image> </Button>
i did like you sayd and only replaced image source and got the error at </Button> that the property can be set only once and Image Source that the property is set more then once
@RedDevil please update your question with the exact new source and exact new error message or ask a new question with those two.
@RedDevil So did I :)
So i noticed with other effects its the same thing but after i click the effect i notice a small line inside the button under the text of the button like the text is SADASDADADSA and under it is a small blur line.But no matter if i press the button or not i dont see the effect apply.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.