C# 微软WPF转换器
所以我今天在MSDN上找到了很多转换器,现在我想使用其中的一些。然而,在搜索了一点之后,我似乎找不到关于它们的任何东西 我主要想用这个。然而,我不知道如何使用转换,因为没有提供如何使用转换的信息(或在谷歌上) 我知道自己制作这个转换器很容易,但我是一个程序员,我的moto是懒惰的,如果可以的话,制作已经存在的方法(转换器)是多余的工作 希望有人能向我解释如何使用这些转换器 编辑: 尝试回复后,加载usercontrol时出现错误:C# 微软WPF转换器,c#,wpf,mvvm,converter,C#,Wpf,Mvvm,Converter,所以我今天在MSDN上找到了很多转换器,现在我想使用其中的一些。然而,在搜索了一点之后,我似乎找不到关于它们的任何东西 我主要想用这个。然而,我不知道如何使用转换,因为没有提供如何使用转换的信息(或在谷歌上) 我知道自己制作这个转换器很容易,但我是一个程序员,我的moto是懒惰的,如果可以的话,制作已经存在的方法(转换器)是多余的工作 希望有人能向我解释如何使用这些转换器 编辑: 尝试回复后,加载usercontrol时出现错误: {"Cannot find resource named 'In
{"Cannot find resource named 'IntToVisibleConverter'. Resource names are case sensitive."}
App.xaml
<Application x:Class="Smartp1ck.JungleTimerClient.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:msconv="clr-namespace:Microsoft.TeamFoundation.Controls.WPF.Converters;assembly=Microsoft.TeamFoundation.Controls">
<Application.Resources>
<msconv:IntToVisibleConverter x:Key="IntToVisibleConverter" />
</Application.Resources>
</Application>
在用户控件上
<TextBlock Text="{Binding TimeLeft}" HorizontalAlignment="Center" Visibility="{Binding Path=TimeLeft, Converter={StaticResource IntToVisibleConverter}}" />
编辑2:
将其放入usercontrol的资源中可以使其工作。太糟糕了,我不能使用app.xaml,因为某种原因,我会在以后再把它弄出来。谢谢你的帮助,解决了
Maxim您必须在应用程序和xaml中添加
Microsoft.TeamFoundation.Controls.dll
作为参考,然后您可以在窗口资源中声明转换器并在应用程序中使用
例如:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mstf="clr-namespace:Microsoft.TeamFoundation.Controls.WPF.Converters;assembly=Microsoft.TeamFoundation.Controls"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<mstf:IntToBoolConverter x:Key="IntToBoolConverter" />
</Window.Resources>
<Grid>
<CheckBox IsChecked="{Binding Path=MyInt, Converter={StaticResource IntToBoolConverter}}" />
</Grid>
</Window>
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mstf="clr-namespace:Microsoft.TeamFoundation.Controls.WPF.Converters;assembly=Microsoft.TeamFoundation.Controls"
StartupUri="MainWindow.xaml">
<Application.Resources>
<mstf:IntToBoolConverter x:Key="IntToBoolConverter" />
</Application.Resources>
</Application>
您可以使用与第一个示例相同的方法访问该应用程序
Converter={StaticResource IntToBoolConverter}
尝试注释掉Textblock
并编译该应用程序,然后再次取消注释,有时VS不会从app.xaml获取更改,直到重新编译,或者,如果您仍然有问题,您可以将转换器添加到您的
,这是app.xaml无法工作的一个bug