我创建了一个自定义转换器。我尝试在页面中定义它。我在 Vb.net 中找不到任何好的例子。由于 C# 之间的命名空间差异,互联网上的资源对我帮助不大。例如,在 Microsoft 的页面上,我看不到它是如何在 XAML 的标题中定义的。
这是我到目前为止所做的,但收到一个错误,即未创建命名空间。
转换器:
Public Class MyConverter
Implements IMultiValueConverter
Public Function Convert(values As Object(), targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IMultiValueConverter.Convert
Return values
End Function
Public Function ConvertBack(value As Object, targetTypes As Type(), parameter As Object,culture As System.Globalization.CultureInfo) As Object() Implements System.Windows.Data.IMultiValueConverter.ConvertBack
Throw New NotSupportedException()
End Function
End Class
XAML 页面:
<Page x:Class="KlantFische"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="MyConverter"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1108"
Title="KlantFische">
<Grid>
<Grid.Resources>
<!-- ERROR: The name "MyConverter" does not exist in the namespace "MyConverter". -->
<local:MyConverter x:Key="SearchTermConverter" />
</Grid.Resources>
</Grid>
</Page>
Imports System.Data
Imports System.Collections.ObjectModel
Imports System.Windows.Threading
Imports System.Windows.Controls.Primitives
Imports System.Text
Imports System.Text.RegularExpressions
Partial Public Class KlantFische
Inherits Page
Public Sub New()
Me.InitializeComponent()
End Sub
End Class
项目布局: