我有一个Silverlight 3导航应用程序,我想在编辑项目时暂时禁用指向各种Silverlight页面的链接,要求用户明确取消编辑,而不是离开屏幕。

[编辑]如何以编程方式暂时禁用导航链接?

有帮助吗?

解决方案

您可以将每个HyperLink上的IsEnabled绑定到全局属性。您可以从代码设置属性,从而禁用导航。

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

其他提示

这是一个猜测而不是答案,但是:

嗯,有一种简单而不优雅的方式,那就是当要编辑的项目获得焦点时强制禁用所有超链接,然后在项目失去焦点时启用它们用户取消它。要做到这一点,你可以抓住内部链接的容器,然后循环它们并禁用或启用它们。

如果导航完全存在于另一个控件中,则可以使用相同的焦点方法和失去焦点将该控件设置为禁用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top