Binding ConvererParameter
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的更多相关文章
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): da.huying.usermanag ...
- WPF binding 参考
Introduction This is an article on WPF Binding Cheat Sheet. Some of the Binding won't work for Silve ...
- 十五天精通WCF——第一天 三种Binding让你KO80%的业务
转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是一个高度封装的框架,作为在wcf食物链最顶端的我们所能做的任务已经简单的不能再简单了, 再简单的话马路上的大妈也能写wcf了 ...
- Binding笔记
Binding基础 绑定某个对象的属性值到控制上,写法如下: public class Order : INotifyPropertyChanged//只要实现此接口 { public event ...
- Data Binding使用技巧
Data Binding 根据变量,自动赋值到各widget. How 1.编写layout文件,这里的layout为: act_data_bind_demo.xml 这里需要先准备变量 在具体的wi ...
- WPF之Binding初探
初学wpf,经常被Binding搞晕,以下记录写Binding的基础. 首先,盗用张图.这图形象的说明了Binding的机理. 对于Binding,意思是数据绑定,基本用法是: 1.在xmal中使用 ...
- [XAML]类似WPF绑定的Binding的读取方法
在WPF的XAML里,依赖属性可以使用基于BindingBase之类的MarkupExtensin 读取XAML时,会自动的把该BindingBase转换为BindingExpressionBase ...
- [ASP.NET MVC 小牛之路]15 - Model Binding
Model Binding(模型绑定)是 MVC 框架根据 HTTP 请求数据创建 .NET 对象的一个过程.我们之前所有示例中传递给 Action 方法参数的对象都是在 Model Binding ...
- 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 ...
随机推荐
- MCU的四个功能
以下来自Atmel Mega128的说明手册: 微控制器(微处理器)Microcontroller(MCU)的四个基本功能为: 1. access memory, 2. perform calcul ...
- 编译2.4.X apache 常见错误
安装高版本的 apr apr-util ./configure prefix=/usr/local/apr ./configure prefix=/usr/local/apr-util -- ...
- 无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用。
在删除northwindcs表时,发生报错,消息 3726,级别 16,状态 1,第 2 行,无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用.此时判断是因为有其他表的外键 ...
- 即时聊天IM之三 XMPP协议客户端库的和Android端框架概述
合肥程序员群:49313181. 合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入) Q Q:408365330 E-Mail:egojit@qq.com smack ...
- 为 iTween 指定特定的回调 : onupdate, oncomplete
问题地址:Specifying a delegate for the value of onupdate in iTween 1.找到 void CallBack 2.修改以下代码: void Cal ...
- touch的属性
touch命令:建立文件 touch的功能并不是用来创建新文件的,创建文件是touch命令的一个特殊情况,touch是用来修改指定的文件的访问和修改时间属性,如果指定的文件不存在,将建立一个新的空 ...
- [转]http-关于application/x-www-form-urlencoded等字符编码的解释说明
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urlen ...
- Leetcode详解Maximum Sum Subarray
Question: Find the contiguous subarray within an array (containing at least one number) that has the ...
- 深度剖析Linux与Windows系统的区别
当我们每个人接触Linux之前,应该先接触的都是windows吧?但我们一般接触Linux后,习惯linux的管理和使用方法后,我们再回过头再来使用windows的时候,内心其实是拒绝的.我们会觉得图 ...
- 新手要想学好Linux系统就必须做好这四件事情
一般情况下,大部分人接触Linux的机会并不多,对Linux平台下的开发更是一无所知.而现在的发展趋势却越来越表明:无论是作为一个优秀的软件开发人员,或是互联网.IT行业的从业人员,掌握Linux是一 ...