逻辑删除画布可见性属性

本文关键字:可见性 属性 删除 | 更新日期: 2023-09-27 18:19:43

我在检索画布可见性属性的状态时遇到了一个小问题。检索页面状态时,画布始终可见,即使它在逻辑删除时已折叠。我尝试了一堆if-else和switch语句,但没有成功。如何修复此错误?提前感谢任何想帮忙的人!

这是代码:

    private const string coachPivotKey = "CoachPivotKey";
    private const string isVisibleKey = "IsVisibleKey";
    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        this.SaveState(coachPivotKey, coachPivot.SelectedIndex);
        this.SaveState(isVisibleKey, canvasNotes.Visibility);
    }
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        coachPivot.SelectedItem = coachPivot.Items[this.LoadState<int>(coachPivotKey)];
        canvasNotes.Visibility = this.LoadState<Visibility>(isVisibleKey);
        base.OnNavigatedTo(e);
    }

LoadState()和SaveState()方法在不同的类中。这些是我在墓碑上看的一段视频:

public static void SaveState(this PhoneApplicationPage phoneApplicationPage, string key, object value)
    {
        if (phoneApplicationPage.State.ContainsKey(key))
        {
            phoneApplicationPage.State.Remove(key);
        }
        phoneApplicationPage.State.Add(key, value);
    }
public static T LoadState<T>(this PhoneApplicationPage phoneApplicationPage, string key)
    {
        if (phoneApplicationPage.State.ContainsKey(key))
        {
            return (T)phoneApplicationPage.State[key];
        }
        return default(T);
    }

逻辑删除画布可见性属性

不要保存System.Windows.Visibility,而是保存指示控件是否可见的bool

this.SaveState(isVisibleKey,coachNotes.Visibility == Visibility.Visible); 

canvasNotes.Visibility = this.LoadState<bool>(isVisibleKey) ? Visibility.Visible : Visibility.Collapsed;