2012-07-25 100 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你會得到錯誤。

相關問題