Microsoft WPF转换器 - c#

因此,我今天在MSDN上找到了list转换器,现在我想使用其中的一些。但是,经过一番搜索,我似乎找不到任何有关它们的信息。

我主要想使用IntToBoolConverter。但是我不知道如何使用转换,因为没有信息提供如何做到这一点(或在谷歌上)。

我知道自己制作这个转换器很容易,但是我是一名程序员,当可以的时候,我的moto是懒惰的,而使已经存在的方法(转换器)成为多余的工作。

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

编辑:

尝试回复后,在加载usercontrol时出现错误:

{"Cannot find resource named 'IntToVisibleConverter'. Resource names are case sensitive."}

应用程式

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

将其放在用户控件的资源中可以使其正常工作。太糟糕了,由于某种原因我无法使用app.xaml,我稍后再加以解决。感谢您的帮助,解决了!

格言

参考方案

您必须在应用程序和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>

如果要在整个应用程序(其他Windows /对话框等)中全局使用转换器,则可以在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>

您可以像第一个示例Converter={StaticResource IntToBoolConverter}一样访问此文件

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php

我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…

将python scikit学习模型导出到pmml - python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…

如何使用PHP从动态输入字段捕获数组值? - javascript

我正在编写一个在线时间跟踪网页,允许用户将学习时间输入该系统。用户将首先输入名称,然后根据日期输入学习时间。一天中可能会有多个学习时间。以下是我第一页的编码,<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"…

jQuery和Gridview更新面板不起作用 - c#

我必须按照某些给定条件实现gridview的闪烁:gridview row blinking based on some conditions我能够成功实现它,但是随后我被要求在5秒钟内自动刷新gridview,为此我使用了ajax更新面板和计时器,但随后出现如下新的JavaScript错误:码: <form id="form1" …