WPF中ConverterParameter不可以绑定,可以通过如下扩展来实现ConverterParameter的Binding:

1.自定义ConverterBindableBinding和MultiValueConverterAdapter:

namespace TTSControl.UtilityClasses
{
    public class ConverterBindableBinding : MarkupExtension
    {
        public Binding Binding { get; set; }

public IValueConverter Converter { get; set; }

public Binding ConverterParameterBinding { get; set; }

public Binding ConverterBinding { get; set; }

public override object ProvideValue(IServiceProvider serviceProvider)
        {
            MultiBinding multiBinding = new MultiBinding();
            multiBinding.Bindings.Add(Binding);
            multiBinding.Bindings.Add(ConverterParameterBinding);
            if (ConverterBinding != null) multiBinding.Bindings.Add(ConverterBinding);
            MultiValueConverterAdapter adapter = new MultiValueConverterAdapter();
            adapter.Converter = Converter;
            multiBinding.Converter = adapter;
            return multiBinding.ProvideValue(serviceProvider);
        }
    }
}

namespace TTSControl.UtilityClasses
{
    [ContentProperty("Converter")]
    public class MultiValueConverterAdapter : IMultiValueConverter
    {
        public IValueConverter Converter { get; set; }

#region IMultiValueConverter Members

private object lastParameter;
        private IValueConverter lastConverter;

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            lastConverter = Converter;
            if (values.Length > 1) lastParameter = values[1];
            if (values.Length > 2) lastConverter = (IValueConverter)values[2];
            if (Converter == null) return values[0];
            return Converter.Convert(values[0], targetType, lastParameter, culture);
        }

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            if (lastConverter == null) return new object[] { value };
            return new object[] { lastConverter.ConvertBack(value, targetTypes[0], lastParameter, culture) };
        }

#endregion

}
}

2。在xaml中绑定:

xmlns:uti="clr-namespace:TTSControl.UtilityClasses"

Binding="{Binding PermissionKey}" Converter="{StaticResource permissionValueConverter}"ConverterParameterBinding="{Binding UserName}" />

3。在自定义Converter类中获取绑定数据:

internal class PermissionValueConverter : DependencyObject, IValueConverter, IMultiValueConverter
    {
       
        // For testing of converter properties, we derice from DependencyObject and add a dependency property.

public String UserName
        {
            get { return (String)GetValue(UserNameProperty); }
            set { SetValue(UserNameProperty, value); }
        }

// Using a DependencyProperty as the backing store for ConcatSign.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(String), typeof(PermissionValueConverter), new UIPropertyMetadata(null));

#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string permissionKey = (string)value;
            string  userName= (string)parameter;

List> PermissionValues = new List>();
            PermissionValues = Database.GetPermissionValue(Properties.Settings.Default.gLanguage, userName, permissionKey);
            return PermissionValues;
  
        }

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

#endregion

#region IMultiValueConverter Members

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Convert(values[0], targetType, values[1], culture);
        }

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            return new object[] { ConvertBack(value, targetTypes[0], parameter, culture) };
        }

#endregion

}

Binding ConvererParameter的更多相关文章

  1. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

    org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): da.huying.usermanag ...

  2. WPF binding 参考

    Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silve ...

  3. 十五天精通WCF——第一天 三种Binding让你KO80%的业务

    转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是一个高度封装的框架,作为在wcf食物链最顶端的我们所能做的任务已经简单的不能再简单了, 再简单的话马路上的大妈也能写wcf了 ...

  4. Binding笔记

    Binding基础  绑定某个对象的属性值到控制上,写法如下: public class Order : INotifyPropertyChanged//只要实现此接口 { public event ...

  5. Data Binding使用技巧

    Data Binding 根据变量,自动赋值到各widget. How 1.编写layout文件,这里的layout为: act_data_bind_demo.xml 这里需要先准备变量 在具体的wi ...

  6. WPF之Binding初探

    初学wpf,经常被Binding搞晕,以下记录写Binding的基础. 首先,盗用张图.这图形象的说明了Binding的机理. 对于Binding,意思是数据绑定,基本用法是: 1.在xmal中使用 ...

  7. [XAML]类似WPF绑定的Binding的读取方法

    在WPF的XAML里,依赖属性可以使用基于BindingBase之类的MarkupExtensin 读取XAML时,会自动的把该BindingBase转换为BindingExpressionBase ...

  8. [ASP.NET MVC 小牛之路]15 - Model Binding

    Model Binding(模型绑定)是 MVC 框架根据 HTTP 请求数据创建 .NET 对象的一个过程.我们之前所有示例中传递给 Action 方法参数的对象都是在 Model Binding ...

  9. Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    主要错误信息如下: HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

随机推荐

  1. go并发和并行

    Go语言的并发和并行 不知道你有没有注意到一个现象,还是这段代码,如果我跑在两个goroutines里面的话: var quit chan int = make(chan int) func loop ...

  2. Git 安装

    安装参考资料: http://lzw.me/a/msysgit-tortoisegit-win-git.html http://blog.csdn.net/qwiwuqo/article/detail ...

  3. Web后台开发技术 经验路线图

    一篇文章:http://www.cnblogs.com/Hiker/archive/2012/11/04/houtaijishu.html

  4. web 打开子窗口提交数据或其他操作后 关闭子窗口且刷新父窗口实现

    父页面 : html连接:<a href="javascript:void(0)" onclick="window.open(子页面URL)">js ...

  5. GoF--外观设计模式

    设计模式--外观模式Facade(结构型): 1. 概述 外观模式,我们通过外观的包装,使应用程序只能看到外观对象,而不会看到具体的细节对象,这样无疑会降低应用程序的复杂度,并且提高了程序的可维护性. ...

  6. 移动端重构实战系列2——line list

    这个line list的名字是我自己起的(大概的意思是单行列表),要实现的东西为sheral的line list,对应的scss组件为_line-list.scss,下图为line-list的一个缩影 ...

  7. HTML5 <input>添加多张图片,可点击弹窗放大。限定4张,可删除。

    点击弹窗放大,需要加入插件. <link rel="stylesheet" href="css/photoswipe.css"> <link ...

  8. 为 iTween 指定特定的回调 : onupdate, oncomplete

    问题地址:Specifying a delegate for the value of onupdate in iTween 1.找到 void CallBack 2.修改以下代码: void Cal ...

  9. 在引用KindEditor编辑器时,运行时出现以下错误:错误46 找不到类型或命名空间名称“LitJson”(是否缺少 using 指令或程序集引用?)

    将asp.net下bin文件夹下的文件LitJSON.dll拷贝到工程的bin目录下,并在工程中添加引用 在后台加入: using LitJson;

  10. 简述alert和console.log的区别

    生活中还是得有发现美好和差别的眼睛~~ 学习前端那么久既然还不知道alert和console.log的差别~~~~ 蓝瘦,香菇~~~ 本菜鸟一直以为alert和console.log其实是一样的用法, ...