2016-11-14 91 views
0

第一关都:对不起,我的英文不好,我通常会说德语。无法编辑列表框,前景

目前我工作的一个大项目,我必须填写列表框,这是我作为“导航控制”用,用从字典字符串。

在这个项目的旧版本中,我手动将字符串放在列表框中,然后我可以将列表框的前景从黑色设置为白色,但在当前版本中,它不再可能。

<StackPanel Grid.Column="0" Orientation="Vertical"> 
     <TextBlock Text=" Navigation" FontSize="16" Margin="10" Foreground="White"/> 

     <ListBox HorizontalAlignment="Stretch" 
      VerticalAlignment="Stretch" 
      HorizontalContentAlignment="Left" 
      Margin="10" 
      MaxHeight="150" 
      BorderBrush="Black" 
      Style="{DynamicResource MetroListBox}" 
      SelectedItem="{Binding SelectedTemplate}" Background="#002B2B2B" 
      ItemsSource="{x:Static models:TemplateRepository.TemplateDictionary}" 
      Foreground="White" 
      DisplayMemberPath="Value"> 
     </ListBox> 
    </StackPanel> 

任何人都可以向我解释为什么这不起作用?

+2

什么被指定在sytle'MetroListBox'中?它可能会改写 – Hank

+1

@Hank,本地值具有[优先](https://msdn.microsoft.com/en-us/library/ms743230(V = vs.110)的.aspx)在风格设置器,但也许是风格重新定义'ItemTemplate'('ListBoxItem')和/或面板样式,因此设置'Foreground'对任何东西都没有影响。 – Sinatr

回答

0

这是很难不喜欢什么是对的ListBox项目模板一些更多的信息猜测?如果项目Foreground设置为

<ListBox x:Name="listBox" ItemsSource="{Binding}" Foreground="Red"> 

在另一方面: 例如,你可以有下面的模板中的资源:

<DataTemplate DataType="{x:Type local:SomeClass}"> 
    <Grid DataContext="{Binding}"> 
     <TextBlock Text="{Binding Path=Name}" Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ListBox}}" /> 
    </Grid> 
</DataTemplate> 

在这种情况下设置Foreground到某一值时会影响的项目,如datatemplate中的某个固定值,然后在ListBox中设置它也不起作用。