Mvvmcross覆盖片段中的样式

时间:2014-09-22 16:13:27

标签: mvvmcross

我需要能够覆盖MvvmCross项目中片段的主题。 我在片段上的OnCreateView代码是:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var ignored = base.OnCreateView(inflater, container, savedInstanceState);
            return this.BindingInflate(Resource.Layout.my_fragment_layout, null);
        }

这个问题是绑定上下文是用片段活动上下文创建的,虽然为了能够覆盖我的片段使用的主题,我需要使用一个不同的上下文格式化我的预定义样式,如下所示:

Context context = new ContextThemeWrapper(Activity, Resource.Style.FragmentStyle);

并且无法覆盖用于克隆MvxBindingContext中的上下文的默认上下文。所以我最终得到了像这样的OnCreateView:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            Context context = new ContextThemeWrapper(Activity, Resource.Style.FragmentStyle);

            if (BindingContext == null)
                BindingContext = new MvxAndroidBindingContext(context, new MvxSimpleLayoutInflater(Activity.LayoutInflater), DataContext);
            else
                this.EnsureBindingContextIsSet(inflater);

            return this.BindingInflate(Resource.Layout.my_fragment_layout, null);
        }

现在正在运行,但我不确定在这里处理绑定上下文构造是否安全。如果只有默认上下文可以覆盖,那将是完美的

由于

0 个答案:

没有答案