0

我是 XAML 世界的新手,我正在摸索很多教程。我坚持的一件事是在对象上调用 .tostring 。

这是我的设置

我有一个绑定到对象列表的列表框我有一个 contentControl 绑定到显示列表框中所选项目的相同列表。

我的 ContentControl 如下:

 <ContentControl Grid.Row="1" Margin="0,3,5,204" Name="Detail" 
  Content="{Binding Source={StaticResource listingDataView}}"
  ContentTemplate="{StaticResource myContentTemplate}" 
   HorizontalAlignment="Right" Width="231"/>

在 myContentTemplate 我有:

<DataTemplate x:Key="myContentTemplate">
            <StackPanel>
                <TextBlock Text="{Binding Path=Name}" />
                <!-- want to call .tostring here-->
            </StackPanel>
        </DataTemplate>

在模板中,我想在当前选择的对象上调用 .tostring 但我不知道该怎么做?

谢谢斯蒂芬

4

1 回答 1

0

看来我问这个太早了。我在另一个问题中找到了答案

如何在 XAML 中引用当前对象

引用该线程的答案:

根据Data Binding Overview,可以使用“/”来表示当前项。然后,您可以根据需要使用以下类型语法在树中上下导航:

Button Content="{Binding }" /> 
Button Content="{Binding Path=/}" /> 
Button Content="{Binding
Path=/Description}" />

希望这对其他人有帮助:)

于 2010-09-15T20:02:34.883 回答