WPF MultiBinding 实现控件 Tooltip 多绑定
2013-08-04 14:06
351 查看
//convert
public class CanBeAppliedDisplayConverter : IMultiValueConverter
{
#region Implementation of IMultiValueConverter
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0].ToString() == string.Empty || values[1].ToString() == string.Empty)
return "";
return values[0].ToString() + values[1].ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
//viewmodel
public class viewmodel : INotifyPropertyChanged
{
private string _name1;
public string name1
{
get { return _name1; }
set
{
_name1 = value;
OnPropertyChanged("name1");
}
}
private string _name2;
public string name2
{
get { return _name2; }
set
{
_name2 = value;
OnPropertyChanged("name2");
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
//xaml
<TextBlock DataContext="{Binding}">
<TextBlock.ToolTip>
<ToolTip >
<TextBlock DataContext="{Binding}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource CanBeAppliedDisplayConverter}">
<Binding Path="name1" />
<Binding Path="name2" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
public class CanBeAppliedDisplayConverter : IMultiValueConverter
{
#region Implementation of IMultiValueConverter
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0].ToString() == string.Empty || values[1].ToString() == string.Empty)
return "";
return values[0].ToString() + values[1].ToString();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
//viewmodel
public class viewmodel : INotifyPropertyChanged
{
private string _name1;
public string name1
{
get { return _name1; }
set
{
_name1 = value;
OnPropertyChanged("name1");
}
}
private string _name2;
public string name2
{
get { return _name2; }
set
{
_name2 = value;
OnPropertyChanged("name2");
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
//xaml
<TextBlock DataContext="{Binding}">
<TextBlock.ToolTip>
<ToolTip >
<TextBlock DataContext="{Binding}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource CanBeAppliedDisplayConverter}">
<Binding Path="name1" />
<Binding Path="name2" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
相关文章推荐
- WPF中控件绑定XML文件,实现修改XML文件即可以改变程序控件内容
- WPF MultiBinding 给数据目标赋值后绑定无效的问题
- #375 – 将Tooltip 于父控件的某个属性绑定(Binding Something in a Tooltip to a Property on the Parent Control)
- WPF实现支持Command绑定的ComboBox控件
- WPF 实现数据结构对象与UI控件的绑定
- WPF数据绑定(一):ListView + BindingList实现列表数据绑定
- 用DropDownList控件绑定XML数据实现省市区三级联动
- WPF快速入门教程之绑定Binding
- 模拟实现WPF的依赖属性及绑定通知机制(4)--模拟实现绑定连动机制
- Android官方DataBinding(十二):双向绑定之反向绑定的InverseBindingMethods改造和实现
- WPF 参照WPF实现Silverlight中的多值绑定特性
- treeview控件(动态数据绑定+整行选择)(WPF)(一)
- C#用继承实现自定义控件 让控件默认绑定一个事件
- [XAML]类似WPF绑定的Binding的读取方法
- WPF控件与控件值的绑定
- WPF入门(四)-WPF+LINQ实现数据绑定、交互及简单datagrid样式
- WPF笔记 ( xmlns引用,Resource、Binding 前/后台加载,重新绑定)
- WPF与MVVM的实现(三)List的数据绑定
- ASP.NET使用Linq to SQL实现基本的增、删、改、查及绑定控件
- MultiActionController绑定表单数据的两种实现方式