示例#1
0
        public object GetConverterParameter()
        {
            object parameter = null;

            if (ConverterParameter != null)
            {
                parameter = ConverterParameter;
            }
            else
            {
                if (!string.IsNullOrEmpty(ConverterParameterName))
                {
                    MemberInfo[] parameterMember = null;
                    if (DataContextSource != null)
                    {
                        parameterMember = DataContextSource.GetType().GetMember(ConverterParameterName);
                        if (parameterMember.Length > 0)
                        {
                            parameter = parameterMember[0].GetValue(DataContextSource);
                        }
                        else
                        {
                            parameterMember = Source.GetType().GetMember(ConverterParameterName);
                            if (parameterMember.Length > 0)
                            {
                                parameter = parameterMember[0].GetValue(Source);
                            }
                        }
                    }
                }
            }

            return(parameter);
        }
示例#2
0
        protected virtual object GetValue()
        {
            Type targetType = null;

            if (Member != null && Source != null)
            {
                var view = Source as IDataContext <object>;
                if (view != null && view.DataContext != null)
                {
                    DataContextSource = view.DataContext;
                    DataContextMember = DataContextSource.GetType().GetMember(Member.Name).FirstOrDefault();

                    if (DataContextMember != null)
                    {
                        targetType = Member.GetMemberType();
                        var dataContextValue = DataContextMember.GetValue(DataContextSource);

                        return(Convert(dataContextValue, Type, ValueConverter));
                    }
                }

                var value = Member.GetValue(Source);
                return(value);
            }

            return(ConvertValue(_Value, targetType));
        }
        public Result.IfSuccess <BindingSource> VisitDataContextSource(DataContextSource dataContextSource, Parameters parameters, Context context)
        {
            var binding     = parameters.Binding;
            var elementName = context.XamlElementNameProvider.GetName(binding);

            context.BindingPathBuilder.AppendLine(
                $@"            {context.BindingSource.Name}.BindSourceDataContextOneWay(
                {binding.Id},
                {TargetCodeGenerator.GetTarget(this.elementType, elementName, parameters.HasCodeBehind)},
                {this.targetValue.GetDependencyProperty()},
                t => {this.targetValue.GetPropertyGetter()});");

            context.ExternAliases.TryAdd(this.elementType);
            return(Result.Success(context.BindingSource));
        }
示例#4
0
        void SetDataContextSource(FrameworkElement fe)
        {
            if (DataContextSource != null)
            {
                DataContextSource.RemovePropertyChangedHandler(FrameworkElement.DataContextProperty, DataContextChanged);
            }
            DataContextSource = fe;
            if (DataContextSource != null)
            {
                DataContextSource.AddPropertyChangedHandler(FrameworkElement.DataContextProperty, DataContextChanged);
            }

            // If a FrameworkElement binds to its own datacontext and the VisualParent is null, we end
            // up here with a null DataContextSource. In this scenario we do not want to update.
            if (DataContextSource != null || IsMentorDataContextBound)
            {
                PropertyPathWalker.Update(DataContextSource == null ? null : DataContextSource.DataContext);
            }
        }