I modified my answer after going through your exact requirement.
You just need to use 2 events in this case when you want to enable your button when the mouse isOver the textbox and when its NOT.
Those 2 events are:
MouseEnter and MouseLeave
These events capture the moment when the cursor is over the control and when its not.
And you need a bool property to bind to your Button inorder to change its Enablity according to the condition*(Mouse over or not)*.
private bool _isBtnEnable = false;
public bool IsBtnEnable
{
get { return _isBtnEnable; }
set
{
_isBtnEnable = value;
OnPropertyChanged("IsBtnEnable");
}
}
And in Xaml:
<Grid>
<StackPanel Orientation="Horizontal">
<TextBox Width="100" Text="{Binding
Txt,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Mouse.MouseEnter="TextBox_MouseEnter"
Mouse.MouseLeave="TextBox_MouseLeave"/>
<Button Width="70" Name="btn" Content="Save" Margin="20,0,0,0"
IsEnabled="{Binding IsBtnEnable,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged
/>
</StackPanel>
</Grid>
And in Xaml.cs:
private void TextBox_MouseEnter(object sender, MouseEventArgs e)
{
IsBtnEnable = true;
}
private void TextBox_MouseLeave(object sender, MouseEventArgs e)
{
if (string.IsNullOrEmpty(Txt)) (Checking if the TextBox is empty,remove it
if regardless of text you want to disable the button on cursor being not over the
TextBox but how will you click Save then because it will get disabled when you moved your mouse)
IsBtnEnable = false;
}
I think this will do the trick you want. :)