Silverlight - 在模板中应用转换器

3

我正在更新一个ListPicker的模板。特别是,我正在尝试样式化完整模式弹出窗口的内容。这些信息似乎在以下代码中定义:

<Popup x:Name="FullModePopup">
  <Border Background="{StaticResource PhoneChromeBrush}">
    <!-- Popup.Child should always be a Border -->
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
      </Grid.RowDefinitions>

      <ContentControl Grid.Row="0" Content="{TemplateBinding FullModeHeader}" 
                      Foreground="{StaticResource PhoneForegroundBrush}" 
                      FontFamily="{StaticResource PhoneFontFamilySemiBold}" 
                      FontSize="{StaticResource PhoneFontSizeNormal}" 
                      HorizontalAlignment="Left" Margin="24 12 0 0"/>
        <ListBox x:Name="FullModeSelector" Grid.Row="1" 
          FontSize="{TemplateBinding FontSize}" 
          Margin="{StaticResource PhoneMargin}">
          <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
              <StackPanel/>
              <!-- Ensures all containers will be available during the Loaded event -->
            </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
        </ListBox>
      </Grid>
    </Border>
  </Popup>

我的挑战是,我需要裁剪此弹出列表中每个项目的文本。 更重要的是,我需要使用转换器完成此操作。 这是否可能? 我该如何在此模板中使用转换器? 传统上,我会使用类似以下内容的东西:

<TextBlock Text="{Binding Path=Name, Converter={StaticResource myConverter}}" />

如何将转换器应用于 ListPicker 弹出窗口中的项目?

谢谢!

1个回答

2

这是您正在寻找的内容吗?

基本上,覆盖itemtemplate,放入textblock并将转换器应用于绑定。

像这样:

<ListBox ItemsSource="{StaticResource customers}" Width="350" Margin="0,5,0,10">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <TextBlock Padding="5,0,5,0"
          Text="{Binding FirstName, Converter={StaticResource yourConverter}}" /> 
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

这里是msdn文档
祝你好运。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接