2009-08-04 18 views
9

मैं एक आइटम नियंत्रण रखना चाहता हूं जिसमें आइटम प्रदर्शित होते हैं क्षैतिजक्यों मेरे आइटम नियंत्रण आइटम में क्षैतिज लेआउट नहीं है?

हालांकि, कोई फर्क नहीं पड़ता अगर मैं StackPanel अभिविन्यास = "क्षैतिज" या WrapPanel साथ उपयोग करते हैं, वे अभी भी टिके रहते हैं।

आइटम आइटम को क्षैतिज रूप से कैसे प्राप्त किया जा सकता है?

alt text http://i31.tinypic.com/dd2et5.png

XAML:

<Window x:Class="TestItemsControl2938.Window1" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Window1" Height="300" Width="400"> 
    <Window.Resources> 
     <DataTemplate x:Key="CustomerListTemplate"> 
      <StackPanel Width="100" Background="#aaa" Margin="5"> 
       <TextBlock Text="{Binding LastName}"/> 
      </StackPanel> 
     </DataTemplate> 
    </Window.Resources>  
    <StackPanel> 
     <StackPanel Orientation="Horizontal" Background="Orange"> 
      <ItemsControl ItemsSource="{Binding CustomerList}" ItemTemplate="{StaticResource CustomerListTemplate}"/> 
     </StackPanel> 
     <WrapPanel Background="Yellow"> 
      <ItemsControl ItemsSource="{Binding CustomerList}" ItemTemplate="{StaticResource CustomerListTemplate}"/> 
     </WrapPanel> 
    </StackPanel> 
</Window> 

कोड-पीछे:

using System.Windows; 
using System.ComponentModel; 
using System.Collections.ObjectModel; 
namespace TestItemsControl2938 
{ 
    public partial class Window1 : Window, INotifyPropertyChanged 
    { 
     private ObservableCollection<Customer> _customerList = new ObservableCollection<Customer>(); 
     public ObservableCollection<Customer> CustomerList 
     { 
      get{ return _customerList; }  
      set 
      { 
       _customerList = value; 
       OnPropertyChanged("CustomerList"); 
      } 
     } 

     public Window1() 
     { 
      InitializeComponent(); 
      DataContext = this; 

      CustomerList.Add(new Customer { FirstName = "Jim", LastName = "Jones" }); 
      CustomerList.Add(new Customer { FirstName = "Joe", LastName = "Adams" }); 
      CustomerList.Add(new Customer { FirstName = "Jake", LastName = "Johnson" }); 
     } 


     public event PropertyChangedEventHandler PropertyChanged; 

     protected void OnPropertyChanged(string propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 

      if (handler != null) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 

    public class Customer 
    { 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 
     public string Street { get; set; } 
     public string Location { get; set; } 
     public string ZipCode { get; set; } 
    } 
} 
+1

आप एक ही प्रश्न कितनी बार भेजेंगे? –

+0

यह जरूरी होना चाहिए। – Max

+0

यह सवाल 3 बार पूछा गया है। कुछ मिश्रण मुझे यकीन है। आईडी हैं: 1228278 (यह एक), 1228270, 1228272. 1228272 अब बंद है। मैं सुझाव देता हूं कि यह एक खुला है, और 1228270 बंद कर रहा है। – Cheeso

उत्तर

30

गलत चारों ओर जिस तरह से। पैनल को कस्टमाइज़ करें जो आइटम्सकंट्रोल अपने आइटमों को रखने के लिए उपयोग करता है:

<ItemsControl> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <StackPanel Orientation="Horizontal"/> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 
+0

मैं कहां 'टेक्स्टब्लॉक टेक्स्ट = "{बाइंडिंग LastName}" /> '?? मैं किसी ऑब्जेक्ट पर बाध्यकारी हूं और मेरे पास बस मेरे ऑब्जेक्ट प्रकार की क्षैतिज सूची है। – Smithy

1

आपको आइटम पैनेल का उपयोग करना चाहिए। देखें here मेरा उत्तर

संबंधित मुद्दे