Die opstel van die Hoogte van ListboxItems In 'n ListBox Programmeer vir Windows Store App

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. Vir hierdie doel, Ek het ook 'n ListBox soos volg:

<ListBox x:Noem ="GameStateLog" HorizontalAlignment ="Center" Hoogte ="221" VerticalAlignment ="Top" Breedte ="499" Padding ="0" Maak lettergrootte ="10">

 

Die C # kode die listbox te bevolk tydens looptyd was langs die lyne van:

GameStateLog.Items.Insert(0, GameStateCounter     + ": Nuwe spel staat: wag vir speler 1 naam");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. Dit maak sin as ek wil einde gebruikers in staat wees om hierdie items te kies, maar nie sin maak toe ek wil net 'n lopende reeks log boodskappe te wys - gebruikers sal nie kies hierdie, just view them. Dit was vreemd hard 'n maklike manier om dit te doen om uit te vind en waarskynlik, the way I found it isn’t necessarily “easy” but I got it working OK. Die sleutel insig het gekom van die plasing hier (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. In plaas van die toevoeging van snare op die items versameling op die ListBox, add ListBoxItems. Deur die toevoeging van 'n string, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. Die nuwe kode is:

        private nietig AddGameStateLogMessage(string theMessage)
        {
            ListBoxItem dat = nuwe ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Dik thisPadding = nuwe Dikte(5, 0, 5, 0);
            li.Padding = thisPadding;

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

 

Here I’m creating ListBoxItem’s and inserting them. Ek verwyder die oortollige padding deur die oprigting van die dikte.

Dit is redelik buigsaam as ek nie van plan sommige kleurkodering bepaalde tipes boodskappe na vore te bring om te doen en deur die direk by ListBoxItems ek kry om te styl hulle enige manier wat ek wil.

Hoop dit help iemand!

</einde>

undefinedSkryf in op my blog.

Volg my op Twitter http://www.twitter.com/pagalvin

Laat 'n antwoord

Jou e-posadres sal nie gepubliseer word nie. Verpligte velde gemerk *