2013-08-19 21 views
0

我已經指定ListBox的內容是一個對象列表。如何綁定到wpf列表框中的所有項目並指定轉換器?

<telerik:RadListBox x:Name="listViewTakeOffConfigurations" 
ItemsSource="{Binding EstimateTakeoffService.EstimatingTakeOffConfigurations}" > 

ItemTemplate設置像這樣:

<telerik:RadListBox.ItemTemplate> 
    <DataTemplate> 
     <Grid> 
      <Grid.ColumnDefinitions> 
      <ColumnDefinition /> 
       <ColumnDefinition /> 
      </Grid.ColumnDefinitions> 
      <TextBlock Text="{Binding Path=FontName}" /> 
      <TextBlock Grid.Column="1" Text="Sample" FontFamily="{Binding FontName}" Foreground="{Binding Path=FontColour, Converter={StaticResource hexColorToBrushConverter}}" FontSize="{Binding Path=FontSize}" FontStyle="{Binding Path=SelectedItem, Converter={StaticResource estimatingTakeOffConfigurationToFontStyleConverter}, Mode=OneWay}" VerticalAlignment="Centre" Margin="5,0,0,0"/> 
     </Grid> 
    </DataTemplate> 
</telerik:RadListBox.ItemTemplate> 

我在第二個文本框與fontstyle的一個問題。我希望它綁定到列表框中的每個項目,這將涉及到我設置一個像{binding}這樣的綁定,但是這不允許我添加一個轉換器,所以fontstyle將不會被設置。

有沒有人有任何建議?

感謝

+0

能否請您提供更多infomration你想用FontStyle做什麼?我們在哪裏應用它?我們應該從轉換器轉換成什麼? – AlSki

回答

0

我想你只需要添加元素的名稱指向回列表框,(假設這就是你正在嘗試做的)

FontStyle="{Binding 
    ElementName=listViewTakeOffConfigurations, 
    Path=SelectedItem, 
    Converter={StaticResource estimatingTakeOffConfigurationToFontStyleConverter}, 
    Mode=OneWay}" 
+0

這不起作用。我不需要包含所選項目,因爲我希望它適用於ListBox的ItemSource中的所有項目。 –

+0

不,所選項目是它的來源。然而,它確實顯示這裏缺少信息。 – AlSki

+0

我已經設法回答我自己的問題。我需要指定路徑,如path =。,這相當於不指定路徑,並允許我添加轉換器。 –