C# 使用数据模板中的文本块转换器

C# 使用数据模板中的文本块转换器,c#,wpf,C#,Wpf,我正在使用ItemsControl绑定字符串集合: <ItemsControl ItemsSource="{Binding MyCollection}"> <ItemsControl.Template> <ControlTemplate> <ItemsPresenter/> </ControlTemplate> </ItemsControl

我正在使用
ItemsControl
绑定字符串集合:

<ItemsControl ItemsSource="{Binding MyCollection}">
     <ItemsControl.Template>
          <ControlTemplate>
                <ItemsPresenter/>
          </ControlTemplate>
     </ItemsControl.Template>
 <ItemsControl.ItemTemplate>
        <DataTemplate>
             <TextBlock Text="{Binding, Converter={local:MyTextConverter}}" />
        </DataTemplate>
 </ItemsControl.ItemTemplate>
 </ItemsControl>


由于语法
{Binding,Converter=…}
,上述代码无法编译,在这种情况下如何使用转换器?

您通常会将转换器声明为资源并执行静态资源查找:

<Window.Resources>
    <local:MyTextConverter x:Key="MyTextConverter"/>
</Window.Resources>
...
<TextBlock Text="{Binding, Converter={StaticResource MyTextConverter}}" />

您通常会将转换器声明为资源并执行StaticResource查找:

<Window.Resources>
    <local:MyTextConverter x:Key="MyTextConverter"/>
</Window.Resources>
...
<TextBlock Text="{Binding, Converter={StaticResource MyTextConverter}}" />

您通常会将转换器声明为资源并执行StaticResource查找:

<Window.Resources>
    <local:MyTextConverter x:Key="MyTextConverter"/>
</Window.Resources>
...
<TextBlock Text="{Binding, Converter={StaticResource MyTextConverter}}" />

您通常会将转换器声明为资源并执行StaticResource查找:

<Window.Resources>
    <local:MyTextConverter x:Key="MyTextConverter"/>
</Window.Resources>
...
<TextBlock Text="{Binding, Converter={StaticResource MyTextConverter}}" />

尝试使用
Converter=“{StaticResource YourConverterKey}”
YourConverterKey
在您的资源中声明如下:

<Local:MyTextConverter x:Key="YourConverterKey"></Local:MyTextConverter>

尝试使用
Converter=“{StaticResource YourConverterKey}”
YourConverterKey
在您的资源中声明如下:

<Local:MyTextConverter x:Key="YourConverterKey"></Local:MyTextConverter>

尝试使用
Converter=“{StaticResource YourConverterKey}”
YourConverterKey
在您的资源中声明如下:

<Local:MyTextConverter x:Key="YourConverterKey"></Local:MyTextConverter>

尝试使用
Converter=“{StaticResource YourConverterKey}”
YourConverterKey
在您的资源中声明如下:

<Local:MyTextConverter x:Key="YourConverterKey"></Local:MyTextConverter>