lisbox顯示爲表格樣式

綁定到自身,設置轉換器,設置borderThickness

<Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self},Converter={StaticResource ListBoxTableBorderConverter}}"/>


public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
          
            ListBoxItem item = (ListBoxItem)value;
            ListBox listView = ItemsControl.ItemsControlFromItemContainer(item) as ListBox; // Use the ItemsControl.ItemsContainerFromItemContainer(item) to get the ItemsControl.. and cast  


            // Get the index of a ListViewItem  
            int index = listView.ItemContainerGenerator.IndexFromContainer(item); // this is a state-of-art way to get the index of an Item from a ItemsControl  

//使用index返回不同表框
        
            return new Thickness(0,0,0,1);
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章