无法设置多重绑定,因为必须指定多值转换器 WPF
Cannot set multibinding because multivalueconverter must be specified WPF
我在使用 WPF 转换器时遇到问题,它给我这个错误 "Cannot set multibinding because multivalueconverter must be specified WPF"。
我查看了一些论坛并找到了一些信息,但它仍然显示错误
我的.cs代码:
namespace Scroll4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
//WindowState = WindowState.Maximized;
InitializeComponent();
}
public class ScrollOffsetToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
throw new ArgumentException("Values cannot be null.");
if (values.Count() != 2)
throw new ArgumentException("Incorrect number of bindings (" + values.Count() + ")");
if (parameter == null)
throw new ArgumentException("Parameter cannot be null.");
var top = parameter.ToString().ToUpper() == "TOP";
var offset = Double.Parse(values[0].ToString());
var maxHeight = Double.Parse(values[1].ToString());
return (top && offset == 0) || (!top && offset == maxHeight) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}
我的xaml:
<Window x:Class="Scroll4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Scroll4"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--ERORR-->
<local:ScrollOffsetToVisibilityConverter x:Key="Converter" />
<SolidColorBrush x:Key="Background" Color="Gray" />...
也许你知道如何修复它?
似乎只是不正确的参考。转换器也有变化。数组有 Count() 方法。可能是你用过 system.linq。只需将 wpfApplication1 更改为您的命名空间
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
//WindowState = WindowState.Maximized;
InitializeComponent();
}
}
public class ScrollOffsetToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
throw new ArgumentException("Values cannot be null.");
if (values.Length != 2)
throw new ArgumentException("Incorrect number of bindings (" + values.Length + ")");
if (parameter == null)
throw new ArgumentException("Parameter cannot be null.");
var top = parameter.ToString().ToUpper() == "TOP";
var offset = Double.Parse(values[0].ToString());
var maxHeight = Double.Parse(values[1].ToString());
return (top && offset == 0) || (!top && offset == maxHeight) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
XAML 文件:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WpfApplication1" >
<Window.Resources>
<local:ScrollOffsetToVisibilityConverter x:Name="ConverterName" x:Key="Converter"/>
</Window.Resources>
<Grid>
<TextBox Text="Hi"/>
</Grid>
</Window>
我在使用 WPF 转换器时遇到问题,它给我这个错误 "Cannot set multibinding because multivalueconverter must be specified WPF"。 我查看了一些论坛并找到了一些信息,但它仍然显示错误
我的.cs代码:
namespace Scroll4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
//WindowState = WindowState.Maximized;
InitializeComponent();
}
public class ScrollOffsetToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
throw new ArgumentException("Values cannot be null.");
if (values.Count() != 2)
throw new ArgumentException("Incorrect number of bindings (" + values.Count() + ")");
if (parameter == null)
throw new ArgumentException("Parameter cannot be null.");
var top = parameter.ToString().ToUpper() == "TOP";
var offset = Double.Parse(values[0].ToString());
var maxHeight = Double.Parse(values[1].ToString());
return (top && offset == 0) || (!top && offset == maxHeight) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}
我的xaml:
<Window x:Class="Scroll4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Scroll4"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<!--ERORR-->
<local:ScrollOffsetToVisibilityConverter x:Key="Converter" />
<SolidColorBrush x:Key="Background" Color="Gray" />...
也许你知道如何修复它?
似乎只是不正确的参考。转换器也有变化。数组有 Count() 方法。可能是你用过 system.linq。只需将 wpfApplication1 更改为您的命名空间
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
//WindowState = WindowState.Maximized;
InitializeComponent();
}
}
public class ScrollOffsetToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
throw new ArgumentException("Values cannot be null.");
if (values.Length != 2)
throw new ArgumentException("Incorrect number of bindings (" + values.Length + ")");
if (parameter == null)
throw new ArgumentException("Parameter cannot be null.");
var top = parameter.ToString().ToUpper() == "TOP";
var offset = Double.Parse(values[0].ToString());
var maxHeight = Double.Parse(values[1].ToString());
return (top && offset == 0) || (!top && offset == maxHeight) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
XAML 文件:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WpfApplication1" >
<Window.Resources>
<local:ScrollOffsetToVisibilityConverter x:Name="ConverterName" x:Key="Converter"/>
</Window.Resources>
<Grid>
<TextBox Text="Hi"/>
</Grid>
</Window>