Bug setting the Visibility of a control that has focus?
Last post 05-09-2008 9:57 PM by coughlinj. 2 replies.
Sort Posts:
05-09-2008 8:39 PM
Bug setting the Visibility of a control that has focus?

 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;
        }
    }
}

 

 

coughlinj

Joined on 03-07-2008
Vancouver
Posts 43
05-09-2008 9:12 PM
Marked as Answer
Re: Bug setting the Visibility of a control that has focus?

Yes definitely a bug, I reported it a while back, I think it will be fixed in the next release. For now, you may have to create your own button to get around it.


Bill Reiss - Client App Dev MVP (What's an MVP?)
Silverlight and XNA Game Development Tutorials at http://www.bluerosegames.com/brg

Bill Reiss

Joined on 05-01-2007
Posts 470
05-09-2008 9:57 PM
Re: Bug setting the Visibility of a control that has focus?

Cool thanks Bill.  I'm just working around it by setting the height to 0 and then back to Double.NaN for now.


No word yet on when the next release will be is there?   Microsoft doesn't have any kind of public roadmap do they?

coughlinj

Joined on 03-07-2008
Vancouver
Posts 43