How to temporarily disable page links in Silverlight 3 navbar?

I have a Silverlight 3 navigation app and I would like to temporarily disable links to various Silverlight pages while editing an element, requiring the user to explicitly undo the edit rather than navigate away from the screen.

[EDIT] How do I temporarily disable navigation links?

+2


source to share


2 answers


You can bind IsEnabled for each HyperLink to a global property. You can set a property from code and thus disable 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;
    }

      

+2


source


This is more of a guess than an answer, but:

Well, there is a simple and not elegant way, and this forces all hyperlinks to be disabled when the element to be edited receives focus, and then activates them when the element loses focus or the user cancels it. To do this, you can grab a container with links inside and skip them, disable or enable.



If the navigation exists entirely in another control, then that control can be disabled by following the same focus and lost focus method.

+1


source







All Articles