开发者

How do I temporarily disable the page links in the Silverlight 3 navigation bar?

I have a Silverlight 3 Navigation Appl开发者_如何学JAVAication 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜