我正在尝试匹配这样的设计..
请注意,“选定的标签颜色色调”是蓝色的,但中心标签的图标应该始终是中间有白色时钟的绿色圆圈。
我已经尝试了很多东西。首先尝试通过使用具有绿色圆圈和时钟 PNG 资源的图层列表 XML 资源以编程方式执行此操作,但根本不起作用。然后我让设计师给了我完整的图标(时钟和绿色圆圈),但现在我遇到了这个问题..
(未选中)
(已选)
我无法找到正确的术语以在 Google 上搜索以解决此问题。
最后,我需要选择的选项卡颜色为蓝色,但我需要中心选项卡图标始终是没有额外颜色的实际图标(本质上它需要看起来与 .png 完全一样)。
PS:我正在使用 Xamarin.Forms、FreshMvvm 和 FreshTabbedFONavigationContainer。但是,通过 Renderer,我可以直接访问 BottomNavigationView 和所有其他原生 Android 组件。因此,解决方案不必是 Xamarin 解决方案。java/kotlin 解决方案也可以使用,我可以将其转换为 Xamarin。
======================
编辑:
======================
所以我使用下面的安德烈斯卡斯特罗代码得到了很多进一步的信息,但我仍然遇到与以前相同的问题。使用下面 Andres 的代码,我切换回使用 FontAwesome 作为图标(效果很好),但这样做意味着我需要使用 aLayerDrawable创建圆形/图标中心选项卡图标。
所以这是我到目前为止..
未选择的中心图标
选定的中心图标
如您所见,未选择时中心图标仍为灰色,选择时为蓝色(其他 4 个图标的正确选择/未选择颜色)。
这是我迄今为止与中心图标有关的代码..
更新选项卡图标
private void UpdateTabbedIcons()
{
for (var i = 0; i < Element.Children.Count; i++) {
var tab = _bottomNavigationView.Menu.GetItem(i);
var element = Element.Children[i];
if (element is NavigationPage navigationPage) {
//if the child …Run Code Online (Sandbox Code Playgroud) android xamarin.android xamarin.forms freshmvvm bottomnavigationview
有没有办法将样式应用于Master of FreshMvvm MasterDetailNavigationContainer中的菜单.简单的样式可以是背景颜色或更改菜单项的字体.我可以看到菜单只是一个带有ListView的简单ContentPage,但没有挂钩?
下面的代码显示了一个 CollectionView 的简单示例。我没有收到 SelectionChangedCommand 的事件。有人可以看到我做错了什么吗?
顺便说一句,完整的源代码可以在 GitHub 上找到。
主页.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ControlDemo"
x:Class="ControlDemo.MainPage">
<StackLayout>
<CollectionView SelectionMode ="Single"
ItemsSource="{Binding Tags}"
SelectionChangedCommand="{Binding SelectedTagChanged}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Label Text="{Binding .}" />
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
主页面模型.cs
public class MainPageModel : FreshBasePageModel
{
public override void Init(object initData)
{
Tags = new List<string>() { "A", "B", "C" };
base.Init(initData);
}
public List<string> Tags { get; set; }
public Command SelectedTagChanged
{
get
{
return new …Run Code Online (Sandbox Code Playgroud) 我在freshmvvm框架中使用了xamarin形式。
我想知道如何才能跳过使用xaml,而仅从c#中的代码访问绑定数据。
是否有任何代码示例可以帮助您?
我正在使用Xamarin Forms(v2.3.1.114)和FreshMVVM实现Master Detail导航,其中第一页是选项卡式导航.为了实现,我正在使用FreshMVVM自定义导航示例.
导航在Android和iOS上运行良好,但在UWP上,主导航按钮不会显示.
这是我导航代码的一部分
FreshTabbedNavigationContainer _mainTabs;
void Setup()
{
_mainTabs = new FreshTabbedNavigationContainer();
_mainTabs.AddTab<MyRewardsPageModel>("My Rewards", null);
_mainTabs.AddTab<MapPageModel>("Map", null);
_mainTabs.AddTab<NearbyPageModel>("Near You", null);
_contactusPage = FreshPageModelResolver.ResolvePageModel<ContactUsPageModel>();
_aboutUsPage = FreshPageModelResolver.ResolvePageModel<AboutUsPageModel>();
}
void CreateMenuPage(string menu)
{
var menuPage = new ContentPage { Title = menu };
var listView = new ListView { ItemsSource = new string[] { "Home", "Contact Us", "About Us" } };
listView.ItemSelected += (sender, args) =>
{
switch ((string)args.SelectedItem)
{
case "Home":
Detail = _mainTabs;
break;
case …Run Code Online (Sandbox Code Playgroud) 我定义了一个XAML页面布局,其中包含一个WebViewHTML字符串:
<WebView HorizontalOptions="Fill" VerticalOptions="FillAndExpand">
<WebView.Source>
<HtmlWebViewSource Html="{Binding Flag.Description}" />
<!-- <HtmlWebViewSource Html="<html><body><p>The HTML string.</p></body></html>" />-->
</WebView.Source>
</WebView>
Run Code Online (Sandbox Code Playgroud)
当我将字符串硬编码到XAML中时,它会正确显示,但它不会绑定到Flag.Description字符串.XAML包含一些正确绑定的标签,但我找不到WebView源未正确绑定的任何原因.
我正在使用 FreshMVVM 框架实现 Xamarin 应用程序,我想使用 BasePage 在页面之间共享一些代码。问题是,当我需要在 MainPage.xaml 中绑定某些属性时,我必须以这种方式指定源才能使其正常工作:Text="{Binding Title, Source={x:Reference mainPage}}"。否则没有源绑定就不起作用。好的,我明白了,但是这是正确的方法吗?还有其他方法可以达到相同的结果吗?当页面中有大量绑定时怎么办?例如,是否可以在上层“设置”源,因为在我看来,为每个绑定设置相同的源是非常烦人的。
基本页.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestXamarin.BasePage"
x:Name="basePage">
<ContentView>
<StackLayout Orientation="Vertical">
<Label Text="HEADER" FontSize="Large"/>
<Label Text="{Binding Text, Source={x:Reference basePage}}" FontSize="Large"/>
<ContentPresenter BindingContext="{Binding Parent.BindingContext}"
Content="{Binding PageContent, Source={x:Reference basePage}}" />
</StackLayout>
</ContentView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
基本页.xaml.cs
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace TestXamarin
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BasePage : ContentPage
{
public static readonly BindableProperty TextProperty = BindableProperty.Create(
nameof(Text),
typeof(string),
typeof(BasePage));
public string Text
{
get { return …Run Code Online (Sandbox Code Playgroud)