views:

232

answers:

2

I have a Silverlight 3 Navigation Application and I would like to temporarily disable the links to the various Silverlight pages when an item is being edited, requiring the user to explicitly cancel the edit rather than navigate away from the screen.

[EDIT] How do I temporarily disable the navigation links programmatically?

+1  A: 

This is more a guess than an answer but:

Well, there is the simple and non-elegant way, and that is to force all the hyper links to be disabled when the item that is about to be edited gains focus, and then enable them when the item loses focus or the user cancels it. To do this, you could grab the container with the links inside, and loop through them and disabling or enabling them.

If the navigation exists in another control entirely, then that control could be set as disabled following the same method of focus and lost focus.

Johannes
+2  A: 

You could bind the IsEnabled on each HyperLink to a global property. You can set the property from code and thereby disable the navigation.

MainPage.cs

public partial class MainPage : UserControl
{
    public bool IsNavigationEnabled
    {
     get { return (bool)GetValue(IsNavigationEnabledProperty); }
     set { SetValue(IsNavigationEnabledProperty, value); }
    }
    public static readonly DependencyProperty IsNavigationEnabledProperty =
     DependencyProperty.Register("IsNavigationEnabled", typeof(bool), typeof(MainPage), null);

    public MainPage()
    {
     InitializeComponent();

     DataContext = this;
    }

...

MainPage.xaml

<HyperlinkButton
    x:Name="Link1"
    IsEnabled="{Binding IsNavigationEnabled}"
    Style="{StaticResource LinkStyle}"
    NavigateUri="/Home"
    TargetName="ContentFrame"
    Content="home" />

Home.xaml.cs

 private void Button_Click(object sender, RoutedEventArgs e)
 {
  MainPage page = (MainPage)Application.Current.RootVisual;
  page.IsNavigationEnabled = !page.IsNavigationEnabled;
 }
xamlgeek
Wow, thanks for spelling it out... much appreciated. I still have a lot to learn about silverlight.
Traples
You're welcome! Silverlight is amazing and you can do some great stuff with it. I learn new tweaks everyday about Silverlight.
xamlgeek