0

我有一个转换器,它有几个输入变量(一个对象和一个文本框),然后返回TextBox.Text字符串属性。

我遇到的问题出在ConvertBack()转换器的方法中。我无法将任何更新链接回对象,因为我得到的只是一个字符串(文本框的文本)。有什么方法可以访问一些(如果不是全部)Convert()变量吗?或者至少知道哪个文本框正在调用ConvertBack()

这是我的 ItemsControl 代码:

<ItemsControl x:Name="ItemsControlGrid" ItemsSource="{Binding Path=ProjectOrganLocation.LesionTypes, Source={StaticResource Locator}}" >
    <ItemsControl.ItemsPanel>
         <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal" />
         </ItemsPanelTemplate>
     </ItemsControl.ItemsPanel>
     <ItemsControl.ItemTemplate>
         <DataTemplate>
              <TextBox Width="75" TextAlignment="Center" >
                   <TextBox.Text>
                         <MultiBinding Converter="{StaticResource LesionTypeConverter}"  >
                              <Binding RelativeSource="{RelativeSource AncestorType={x:Type TreeViewItem}}" Path="DataContext.OrganLocation"/>
                              <Binding RelativeSource="{RelativeSource Self}" Path="." />
                          </MultiBinding>
                    </TextBox.Text>
                </TextBox>
            </DataTemplate>
      </ItemsControl.ItemTemplate>
 </ItemsControl>

这是我的转换器的一个片段:

List<CategoryCode> Lesions = organ.getLesionTypes;

    if (organ.OrganDisplayName == organ.CurrentOrgan)
       organ.Count++;
    else
    {
       organ.Count = 0;
       organ.CurrentOrgan = organ.OrganDisplayName;
    }
return organ.Labels[organ.Count].LabelPrefix;
4

2 回答 2

4

您最好的选择是在转换器类中添加一个私有属性并在转换期间存储您的值,以便 ConvertBack 可以访问它们。不过,您需要为每个绑定使用单独的转换器实例。

你想达到什么目的?可能有比转换器更好的方法

于 2011-06-17T18:19:48.763 回答
0

如果您在后面的代码中分配绑定,则可以向转换器添加一个构造函数,该构造函数将发送文本框(或任何其他数据)作为参数并记录它。

于 2011-06-17T18:24:57.487 回答