Replies: 3 comments 7 replies
-
@ali50m How about MultiBinding? |
Beta Was this translation helpful? Give feedback.
-
@lindexi 不是很好用, 在执行Convert的时候有object[] values可以使用多个参数, 但是在执行IMultiValueConverter的ConvertBack的时候, 传入参数只有value (另外一个参数Type[] targetTypes几乎没什么用处), 容易缺少上下文信息. 如果有一个可供绑定的parameter,会直观和方便很多. 我遇到的实际问题如下, 我使用了一组RadioButton来表示页面导航按钮, RadioButton的IsChecked通过多值绑定到SelectedEnum和菜单Enum上. 在进行 如果有 converter简化代码如下 public sealed class NavigationMenuSelectionMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[0] is not { } selectedMenu)
return false;
if (values[1] is not { } navigationValue)
return false;
var b = selectedMenu.Equals(navigationValue);
return b;
}
public object[] ConvertBack(
object value,
Type[] targetTypes,
object parameter,
CultureInfo culture
)
{
return value is true
// 这里不好实现, 缺乏上下文绑定信息
? new[] { _navigationValue ?? Binding.DoNothing, Binding.DoNothing }
: new[] { Binding.DoNothing, Binding.DoNothing };
}
} 内容比较多, 怕用英文说不太清除. 如果有需要, 我能提供一部分的英文信息. There is a lot of content, so I'm afraid it won't be clear enough with bad English. If necessary, I can try to provide part of the information in English. |
Beta Was this translation helpful? Give feedback.
-
另外,如果在Style或者controlTemplate里使用converter, 而parameter不能被绑定的话, 那converter就失去了一部分传入绑定信息的功能了. |
Beta Was this translation helpful? Give feedback.
-
It would be much more convenient if WPF can make the ConverterParameter bindable for value converter or introduce new contract for the converters. The value converter will be much more powerful then.
Not sure if it has been asked as I haven`t seen any results with search.
Beta Was this translation helpful? Give feedback.
All reactions