I get an application crash when I set the Visibility of a Button in code through its own Click Method. I figured this had something to do with the button having focus at the time I'm trying to hide it so I attempted to set focus to another control first but this still didn't work. Any ideas?
Here is my XAML...
<UserControl x:Class="SilverlightBugs.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<Button x:Name="breakButton" Content="Click Me it breaks" Click="breakButton_Click" />
<Button x:Name="workButton" Content="Click Me it works" Click="workButton_Click" />
</StackPanel>
</Grid>
</UserControl>
Here is my code file...
using System.Windows;
using System.Windows.Controls;
namespace SilverlightBugs
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void breakButton_Click(object sender, RoutedEventArgs e)
{
workButton.Focus();
breakButton.Visibility = Visibility.Collapsed;
}
private void workButton_Click(object sender, RoutedEventArgs e)
{
if (breakButton.Visibility == Visibility.Visible)
breakButton.Visibility = Visibility.Collapsed;
else
breakButton.Visibility = Visibility.Visible;
}
}
}