2
我想爲我的uwp應用程序使用後退按鈕。我爲此使用了下面的代碼。但它不可見。請幫幫我。在uwp標題欄中的後退按鈕不可見
public class TitleBarBehavior : DependencyObject, IBehavior
{
public DependencyObject AssociatedObject { get; private set; }
public void Attach(DependencyObject associatedObject)
{
var newTitleBar = associatedObject as UIElement;
if (newTitleBar == null)
throw new ArgumentException(
"TitleBarBehavior can be attached only to UIElement");
Window.Current.SetTitleBar(newTitleBar);
}
public void Detach() { }
public bool IsChromeless
{
get { return (bool)GetValue(IsChromelessProperty); }
set { SetValue(IsChromelessProperty, value); }
}
public static readonly DependencyProperty IsChromelessProperty =
DependencyProperty.Register("IsChromeless",
typeof(bool),
typeof(TitleBarBehavior),
new PropertyMetadata(false, OnIsChromelessChanged));
private static void OnIsChromelessChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
CoreApplication.GetCurrentView().TitleBar
.ExtendViewIntoTitleBar = (bool)e.NewValue;
}
}
和app.xaml.cs代碼
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
//SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
Frame FromrootFrame = Window.Current.Content as Frame;
strpage = FromrootFrame.Content.ToString();
//if (rootFrame != null)
//{
// Type whatpageisit = rootFrame.SourcePageType;
// // handle this page type
//}
if (FromrootFrame.CanGoBack)
{
e.Handled = true;
FromrootFrame.GoBack();
}
}
但我得到的錯誤是 「類型 'IBehavior' 兩個「Microsoft.Xaml.Interactivity存在,版本= 2.0 .0.0,Culture = neutral,PublicKeyToken = null'和'Microsoft.Xaml.Interactivity,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e3''
任何人都可以請告訴我如何解決它。
我已經加入同一裝配Microsoft.Xaml.Interactivity 2個的NuGet包,現在我有刪除一個然後也後面的按鈕不visi BLE。但沒有錯誤。 – Archana