0

I learning WPF and build an simple application. This is my button:

<Button x:Name="btnAddFiles" Content="Add" HorizontalAlignment="Left" Margin="1046,34,0,0" VerticalAlignment="Top" 
        Width="111" Height="34" FontSize="20" Foreground="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" 
        Background="{x:Null}" MouseEnter="btnAddFiles_MouseEnter" BorderBrush="Transparent" />

And this is how it looks like:

http://s27.postimg.org/h0iq4mrrz/image.png

I have changed the button background color to Transparent so the background color the you see is all my application background color. All i want to do is when the mouse is over the button change the background color to Transparent. Currently this is the current when mouse is over:

http://s30.postimg.org/x61ssujnx/image.png?noCache=1411485462

So i registered to MouseEnter event:

private void btnAddFiles_MouseEnter(object sender, MouseEventArgs e)
{
    //btnAddFiles.Background = // change the color
}

But i can see that btnAddFiles.Background require Brush and nor Color Any idea hot to change it ?

roz wer
  • 101
  • 1
  • 2
  • 8

1 Answers1

0

i couldn't see your pictures but this is how we change back color in wpf:

btnAddFiles.Background = Brushes.Transparent;

and you can use your code in a mouse enter and mouse leave event.

1st Edit

private void btnAddFiles_MouseEnter(object sender, MouseEventArgs e)
{
    btnAddFiles.Background = Brushes.Transparent;
}

private void btnAddFiles_MouseLeave(object sender, MouseEventArgs e)
{
    btnAddFiles.Background = Brushes.Lime;
}

2nd Edit:

for changing border color and thickness:

button1.BorderBrush = Brushes.Red;
Thickness t = new Thickness(5, 5, 5, 5);
button1.BorderThickness = t;

also change your margin, it is out form. try for example

Margin="50,50,0,0"

let me know if you get your answer.

Masoud Mohammadi
  • 1,721
  • 1
  • 23
  • 41
  • Something is very strange, when the mouse leave the application all the application color changed to Lime. BTW can i make the border when the mouse over the control transparent too ? – roz wer Sep 23 '14 at 19:43
  • you should change your button background but it seems you have changed your application background to lime. make a new project and test my code without any other changes in your code it will work fine. and for the border i am editing my answer. – Masoud Mohammadi Sep 23 '14 at 21:33
  • The problem that all my form changed solved, i put your code inside my button MouseEnter event and after the mouse is over the button i can still see the button border (the button rectangle that marked in some color) - any idea how to make it invisible ? – roz wer Sep 24 '14 at 03:28
  • in border thickness change all 5 to 0 then you don't have any border. Thickness t = new Thickness(0, 0, 0, 0); – Masoud Mohammadi Sep 24 '14 at 08:57
  • I want all the rectangle to dispensary, with Thickness(0, 0, 0, 0) this is not the case – roz wer Sep 24 '14 at 10:11
  • i didn't understand what you said. you don't need thickness in this code. according to your question you wanted to know how to use brush and i answered that, now if you have a new question so ask a new question don't put all your questions in this post. – Masoud Mohammadi Sep 24 '14 at 16:41