微软WPF转换器 [英] Microsoft WPF converters

查看:192
本文介绍了微软WPF转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我今天发现转换器的列表 MSDN上,现在我想用其中的一些。搜索了一下后,不过,我可以T似乎找到他们什么。

So I found a list of Converters on MSDN today, now I want to use some of them. However after searching a bit I can t seem to find ANYTHING about them.

我主要是想使用的 IntToBoolConverter 。但是我不知道如何使用转换由于提供如何做到这一点(或谷歌)没有资料。

I mainly want to use the IntToBoolConverter. However I got no clue how to use the convert since there is no info provided how to do it(or on google).

我知道这很容易使该转换器我自己,但我是一个程序员,我的摩托车是偷懒的时候可以和制作方法(变流器)已经存在是多余的工作。

I know it is easy to make this converter myself, but I am a programmer and my moto is be lazy when you can and making methods(converters) that already exists is redundant work.

希望有人能向我解释。如何使用这些转换器

Hope someone can explain to me how to use these converters.

编辑:

努力的答复后,我得到加载用户控件的错误:

After trying the reply I get error on loading the usercontrol:

{"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}}" />



EDIT2:

思想促进它在UserControl的资源使得它的工作。可惜我可以T选用出于某种原因,我稍后会figuere出来的App.xaml中。感谢您的帮助,解决了!

Puting it in the Resources of the usercontrol makes it work. Too bad I can t use the app.xaml for some reason I ll figuere it out later. Thanks for the help, solved!

马克西姆

推荐答案

您必须添加 Microsoft.TeamFoundation.Controls.dll 为您的应用程序和XAML的引用,那么你就可以在你的窗口资源申报转换器和应用程序中使用。

You will have to add Microsoft.TeamFoundation.Controls.dll as a reference in your app and xaml, then you can declare the converter in your window resources and use in your application.

例如:

<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>

如果你想在全球范围内使用转换器在整个应用程序(其它窗口/对话框等),你可以定义在的App.xaml

If you want to use the converter globally throughout your application (other windows/dialogs etc) you can define the converter in the App.xaml

例如:

<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>

您可以访问此相同,第一个例子转换器= {StaticResource的IntToBoolConverter }

you can access this the same as the first example Converter={StaticResource IntToBoolConverter}

这篇关于微软WPF转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆