Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何临时禁用Silverlight 3导航栏中的页面链接?_Silverlight_Silverlight 3.0_Navigation - Fatal编程技术网

如何临时禁用Silverlight 3导航栏中的页面链接?

如何临时禁用Silverlight 3导航栏中的页面链接?,silverlight,silverlight-3.0,navigation,Silverlight,Silverlight 3.0,Navigation,我有一个Silverlight 3导航应用程序,我想在编辑项目时暂时禁用指向各个Silverlight页面的链接,要求用户明确取消编辑,而不是离开屏幕 [编辑]如何以编程方式临时禁用导航链接?这与其说是答案,不如说是猜测,但: 嗯,有一种简单而不优雅的方法,那就是当要编辑的项目获得焦点时,强制禁用所有超链接,然后在项目失去焦点或用户取消它时启用它们。要做到这一点,您可以抓取其中包含链接的容器,并在其中循环并禁用或启用它们 如果导航完全存在于另一个控件中,则该控件可以按照相同的聚焦和失去焦点方法设

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


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

这与其说是答案,不如说是猜测,但:

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


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

您可以将每个超链接上的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" />

哇,谢谢你把它拼出来。。。非常感谢。关于silverlight我还有很多要学的。不客气!Silverlight非常棒,你可以用它做一些很棒的事情。我每天都在学习有关Silverlight的新技巧。
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MainPage page = (MainPage)Application.Current.RootVisual;
        page.IsNavigationEnabled = !page.IsNavigationEnabled;
    }