შექმნის სიმაღლე ListboxItems In ListBox პროგრამულად for Windows მაღაზია ოთახი

I’m working on a windows store application and one of the things I want to do in the app is display a log that shows status messages and other informational tidbits as the user works things. ამ მიზნით, მე დასძინა ListBox შემდეგი რედაქციით:

<ListBox x:სახელი ="GameStateLog" HorizontalAlignment ="ცენტრი" სიმაღლე ="221" VerticalAlignment ="ყველაზე" ტელეკომპანია"499" Padding ="0" FontSize ="10">

 

C # კოდს populate listbox at runtime იყო გასწვრივ ხაზი:

GameStateLog.Items.Insert(0, GameStateCounter     + ": ახალი თამაში სახელმწიფო: ველოდებით მოთამაშეს 1 სახელი");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. ეს აზრი თუ მინდა ბოლომდე მომხმარებლებს შეძლებს შეარჩიოს ეს ნივთები, მაგრამ არ აქვს აზრი, როდესაც უბრალოდ მინდა ნახოთ გაშვებული სერია ჟურნალის - წევრებს არ შეარჩიოს ეს, just view them. ეს იყო უცნაურად უჭირს მარტივი გზა ამის და სავარაუდოდ, the way I found it isn’t necessarily “easy” but I got it working OK. გასაღები რისთვისაც მოვიდა ამ გამოქვეყნება აქ (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. იმის ნაცვლად, დასძინა strings to ნივთი შეგროვების ListBox, add ListBoxItems. დამატებით სიმებიანი, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. ახალი კოდექსი არის:

        შეტყობინების ცნოს AddGameStateLogMessage(სიმებიანი theMessage)
        {
            ListBoxItem რომ = ახალი ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            სიმძლავრე thisPadding = ახალი სიმძლავრე(5, 0, 5, 0);
            li.Padding = thisPadding;

            GameStateLog.Items.Insert(0,li);
        }

 

Here I’m creating ListBoxItem’s and inserting them. მე ამოღებულ ჭარბი padding მიიღწევა მისი სისქე.

ეს არის საკმაოდ მოქნილი, როგორც მე ვაპირებ ზოგიერთი ფერადი კოდირების ხაზი გავუსვა კონკრეტული სახის შეტყობინებები და უშუალოდ დასძინა ListBoxItems მივიღებ სტილი მათ არანაირად მინდა.

იმედი მაქვს, ეს ეხმარება ვინმე!

</ბოლო>

undefinedგამოწერა ჩემი დღიური.

გამომყვეს Twitter-ზე http://www.twitter.com/pagalvin

დატოვე პასუხი

თქვენი ელ-ფოსტა არ გამოქვეყნდება. აუცილებელი ველები მონიშნულია *