2011-08-05 42 views
3

我目前正在更新ListPicker的模板。特別是,我試圖設計完整模式彈出窗口的內容。此信息顯示在下面的代碼中定義:Silverlight - 在模板中應用轉換器

<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的Popup中的項目?

謝謝!

回答

2

這是你在找什麼?

基本上覆蓋itemtemplate,放入一個文本塊,並將您的轉換器應用於綁定。

像這樣

<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文檔

HTH

+0

哇!非常感謝! – user609886