Xamarin navigation bar has unwanted default icon, impossible to alter or remove

浪子不回头ぞ 提交于 2019-12-11 21:12:43

问题


Recently I upgraded my Xamarin project to all the latest DLLs. Now on the navigation bar an icon has appeared on Android (haven't looked at iOS yet). See generic icon:

After spending hours searching and prototyping code I still can't figure out how to change or get rid of the icon! Doing a recursive search for png files in my project finds no such image.

There is a method SetTitleIcon but that method doesn't do anything. Some people talk about a toolbar xaml file in the layout folder, but I have no such file.

I followed this tutorial: https://xamarinhelp.com/xamarin-forms-toolbar/ but can only add icons, it doesn't remove the default icon.

I found this demo project: https://developer.xamarin.com/samples/monodroid/Supportv7/AppCompat/Toolbar but that code is quite different from mine. Do I need to go that route?

Anyway, my main xaml file:

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SharedMobile"
             NavigationPage.HasNavigationBar="true"
             x:Class="SharedMobile.MainPage">

  <MasterDetailPage.Master>
    <local:MainPageMaster x:Name="MasterPage" />
  </MasterDetailPage.Master>
  <MasterDetailPage.Detail>
        <NavigationPage BarBackgroundColor="#DCDCDC"> 
      <x:Arguments>
         <local:ActionProcessesPage />
      </x:Arguments>
    </NavigationPage>
  </MasterDetailPage.Detail>
</MasterDetailPage>

There is little to no mention anywhere else in the project of a navigation bar. I did try to add a NavigationPage.Icon under the Navigation Page. Nothing happened.

I only do Xamarin part-time is my excuse.


回答1:


One of the main reasons I post on Stack Overflow is often (for some reason) shortly after posting I will figure out or find the answer.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SharedMobile;assembly=MyApp.Mobile"
             NavigationPage.TitleIcon="transparent.png"
             x:Class="SharedMobile.ActionProcessesPage">


来源:https://stackoverflow.com/questions/55188043/xamarin-navigation-bar-has-unwanted-default-icon-impossible-to-alter-or-remove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!