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 ...
随机推荐
- PHPStorm技巧篇 -- 全局搜索
自定义快捷键,找到search everywhere 我绑定的是alt+N 设置好并apply后,在项目中使用:快捷键alt+N ,输入自己需要查找的文件或类名或方法名,即可出现相应的选项. so c ...
- 用到的一些python包,记录下
Requests beautifulsoup lxml logging gevent django Bottle numpy pandas sklearn pyopencv opencv_python ...
- Python之路 day2 按行读文件
#1. 最基本的读文件方法: # File: readline-example-1.py file = open("sample.txt") while 1: line = fil ...
- webbench---linux压测工具
webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好用,安装使用也特别方便,并且非常小. 1.适用系统:Linux-CentOs 2.编译安 ...
- webStorage和cookie的区别
共同点: 都是保存在浏览器端,且同源的 cookie有什么缺点? Cookie数量和长度的限制.每个domain最多只能有20条cookie,每个cookie长度不能超过4KB 安 ...
- SQL SERVER 2005 DBCC PAGE命令说明
夏日福利: 小泽玛利亚的“专业摄影”性感写真集:http://947kan.com/video/player-52475-0-0.html ------------------------------ ...
- 51nod 1622 集合对[算法马拉松19 C]
题目链接:https://www.51nod.com/contest/problem.html#!problemId=1622 第一次参加算法马拉松,我就是去看大神们疯狂秒题,然后感受绝望的orz.. ...
- python类中super()和__init__()的区别
class Base(object): def __init__(self): print 'Base create' class childB(Base): def __init__(sel ...
- Python 对不均衡数据进行Over sample(重抽样)
需要重采样的数据文件(Libsvm format),如heart_scale +1 1:0.708333 2:1 3:1 4:-0.320755 5:-0.105023 6:-1 7:1 8:-0.4 ...
- Ext4 ComboBox组件使用
先来看例子: Ext.define('schoolModel', { extend: 'Ext.data.Model', fields: [{ name: 'id', type: 'string' ...