Ich versuche, Zurück-Taste für meine uwp App zu verwenden. Ich verwende den folgenden Code dafür. Aber es ist nicht sichtbar. Bitte hilf mir.Zurück-Taste in der Titelleiste in uwp nicht sichtbar
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;
}
}
und der Code in 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();
}
}
Aber die Fehler, die ich bekommen habe ist "Der Typ 'IBehavior' sowohl‚Microsoft.Xaml.Interactivity existiert, Version = 2.0 .0.0, Kultur = neutral, PublicKeyToken = null 'und' Microsoft.Xaml.Interactivity, Version = 12.0.0.0, Kultur = neutral, PublicKeyToken = 31bf3856ad364e3 '"
kann mir bitte jemand sagen, wie ich es lösen kann.
I 2 nuget Pakete von derselben Baugruppe Microsoft.Xaml.Interactivity hinzugefügt haben, jetzt habe ich Entfernte man dann auch den Zurück-Button ist nicht visi ble. Aber es gibt keinen Fehler. – Archana