Further research showed that the problem is that the mouse input event for the button does not always fire. He does most of the time, but either initially, or after the button was hidden (or crashed), the event does not fire. If I move to another case when the buttons must be activated, this will happen. Even setting the ZIndexbuttons on 9999 doesn't seem to help.
I rewrote the code to use Bindings to set the button image source and visibility, and the problem still shows the same symptoms.
The first time the buttons are visible (but do not display an image) when the mouse moves over them, they do not display a tooltip or are not displayed. If I switch to another album using the keyboard / mouse keys, the buttons will start behaving. If I choose again, and the next artist will have several albums, the buttons will start behaving.
Old name:
Why is my button activation code not working?
I am experimenting with the user interface when certain buttons are active only under certain conditions and become visible only when the mouse moves around their location. (NOTE: I am really thinking of abandoning this approach, but I would like to know why my code is not working.)
The problem is that in some circumstances the button is not activated.
, , ( - ), , .
. , , .
, , - , , .
XAML:
<BitmapImage x:Key="NextAlbumSource" CacheOption="OnLoad"
CreateOptions="IgnoreImageCache" UriSource="resources/next.png"/>
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:AlbumChooser.Next}"
CanExecute="NextCanExecute" Executed="NextExecuted" />
</Window.CommandBindings>
<Button Height="50" Width="50" Margin="0,0,10,155"
Command="{x:Static local:AlbumChooser.Next}" Name="NextAlbum"
ToolTip="Next Album" HorizontalAlignment="Right"
VerticalAlignment="Bottom"
MouseEnter="NextAlbum_MouseEnter" MouseLeave="NextAlbum_MouseLeave">
<Image />
</Button>
"MouseEnter" :
private void NextAlbum_MouseEnter(object sender, MouseEventArgs e)
{
if (haveAlbum && moreAlbumsBySameArtist)
{
((sender as Button).Content as Image).Source = this.nextImage;
}
}
, , . .
"MouseLeave" ( ):
private void NextAlbum_MouseLeave(object sender, MouseEventArgs e)
{
((sender as Button).Content as Image).Source = null;
}
, , , ( ) .
Visibility navigationVisiblity = haveAlbum && moreAlbumsBySameArtist
? Visibility.Visible : Visibility.Hidden;
this.NextAlbum.Visibility = navigationVisiblity;
NextCanExecute - :
private void NextCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = haveAlbum && moreAlbumsBySameArtist;
e.Handled = true;
}
(, ).
:
haveAlbum !string.IsNullOrEmpty(this.albumPath.Text)
moreAlbumsBySameArtist - .
UPDATE
, Opacity , Source, . , , . , , ?
? Visibility - -, Visible, ?