2012-07-25 57 views
0

之前是空的(无例外):项目集合必须使用的ItemsSource

<ListBox ItemsSource="{Binding EdgedBoards}" SelectedItem="{Binding SelEdgedBoard, Mode=TwoWay}" DisplayMemberPath="Name"> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="{x:Type ListBoxItem}" 
       BasedOn="{StaticResource {x:Type ListBoxItem}}"> 

      <Setter Property="IsSelected" 
        Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
     </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

我的列表框与DataTrigger

<ListBox ItemsSource="{Binding EdgedBoards}" SelectedItem="{Binding SelEdgedBoard, Mode=TwoWay}" DisplayMemberPath="Name"> 
    <Style TargetType="{x:Type ListBox}" BasedOn="{StaticResource {x:Type ListBox}}"> 
     <Setter Property="Focusable" Value="True" /> 

     <Style.Triggers> 
      <DataTrigger Binding="{Binding ElementName=EdgedBoardsAdd_UC, Path=Visibility}" Value="Visible"> 
       <Setter Property="Focusable" Value="False" /> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 

    <ListBox.ItemContainerStyle> 
     <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"> 
      <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> 
     </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

后面的代码有什么问题?

回答

6

您没有正确声明样式,因此它被设置为列表框的内容 - 您手动声明了包含单个样式的列表。

你应该与<ListBox.Style>元素包装现有Style元素来解决这个问题。

3

您添加了Style作为项目,您忘记了ListBox.Style标签。既然你也试图绑定ItemsSource你会得到错误。

相关问题