在 UWP 应用程序中使用 Catel 转换器
Using Catel Converters in UWP Apps
我正在尝试在 Catel.MVVM.Converters
命名空间中使用 BooleanToCollapsingVisibilityConverter
,但 XAML 设计器未找到该类型并破坏了构建:
XLS0414 The type 'converters:BooleanToCollapsingVisibilityConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
我已经重新启动 Visual Studio,重建了项目,清除了构建缓存,在空白的 UWP 项目中进行了尝试 - 但都无济于事。在正常代码中,我可以毫无问题地实例化转换器。我已经紧紧跟着Catel Documentation了。我做错了什么?
重现问题的示例代码:
<controls:Page
x:Class="App1.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Catel.Windows.Controls"
xmlns:converters="using:Catel.MVVM.Converters"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Border Background="Black" Width="500" Height="500" Visibility="{Binding Visible, Converter={converters:BooleanToCollapsingVisibilityConverter}}"/>
<Button Command="{Binding ToggleVisibility}">Toggle Visibility</Button>
</Grid>
</controls:Page>
通过将 Converter 声明为静态资源解决了问题:
<Page.Resources>
<converters:BooleanToCollapsingVisibilityConverter x:Key="BoolToVisibilityConverter"/>
</Page.Resources>
以后用作
Visibility="{Binding Visible, Converter={StaticResource BoolToVisibilityConverter}}"
我正在尝试在 Catel.MVVM.Converters
命名空间中使用 BooleanToCollapsingVisibilityConverter
,但 XAML 设计器未找到该类型并破坏了构建:
XLS0414 The type 'converters:BooleanToCollapsingVisibilityConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
我已经重新启动 Visual Studio,重建了项目,清除了构建缓存,在空白的 UWP 项目中进行了尝试 - 但都无济于事。在正常代码中,我可以毫无问题地实例化转换器。我已经紧紧跟着Catel Documentation了。我做错了什么?
重现问题的示例代码:
<controls:Page
x:Class="App1.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Catel.Windows.Controls"
xmlns:converters="using:Catel.MVVM.Converters"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Border Background="Black" Width="500" Height="500" Visibility="{Binding Visible, Converter={converters:BooleanToCollapsingVisibilityConverter}}"/>
<Button Command="{Binding ToggleVisibility}">Toggle Visibility</Button>
</Grid>
</controls:Page>
通过将 Converter 声明为静态资源解决了问题:
<Page.Resources>
<converters:BooleanToCollapsingVisibilityConverter x:Key="BoolToVisibilityConverter"/>
</Page.Resources>
以后用作
Visibility="{Binding Visible, Converter={StaticResource BoolToVisibilityConverter}}"