Arkivji tal-Kategorija: XAML

Twaqqif tal-għoli tal ListboxItems Fil-listbox programmatically għall-Windows Aħżen 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. Biex dan il-għan, I miżjuda listbox kif ġej:

<Listbox x:Isem ="GameStateLog" HorizontalAlignment ="Center" Għoli ="221" VerticalAlignment ="Top" Wisa ="499" Padding ="0" FontSize ="10">

 

Il-kodiċi C # biex timla l-listbox fil runtime kien fuq il-linji ta ':

GameStateLog.Items.Insert(0, GameStateCounter     + ": Istat logħba ġdida: stennija għall player 1 isem");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. Li jagħmel sens jekk irrid utenti finali biex tkun tista 'tagħżel dawn l-oġġetti, iżda ma jagħmilx sens meta I biss jixtiequ juru serje kurrenti ta' messaġġi log - utenti mhux se tagħżel dawn, just view them. Kien stramba diffiċli li ssib mod faċli biex jagħmlu dan u forsi, the way I found it isn’t necessarily “easy” but I got it working OK. L-għarfien ewlieni ġew minn din il-kariga hawn (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. Minflok ma żżid kordi għall-ġbir Punti fuq l-listbox, add ListBoxItems. Billi żżid string, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. Il-kodiċi l-ġdid huwa:

        privat null AddGameStateLogMessage(string theMessage)
        {
            ListBoxItem li = ġdid ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Ħxuna thisPadding = ġdid Ħxuna(5, 0, 5, 0);
            li.Padding = thisPadding;

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

 

Here I’m creating ListBoxItem’s and inserting them. I jitneħħew l-ikkuttunar żejjed billi jistabbilixxi ħxuna tagħha.

Dan huwa pretty flessibbli kemm I do intenzjoni li jagħmlu xi kulur kodifika biex jenfasizzaw tipi partikolari ta 'messaġġi u billi żżid direttament ListBoxItems nasal biex istil lilhom b'xi mod irrid.

Nittama li dan jgħin xi ħadd!

</aħħar>

undefinedAbbona għall-blog tiegħi.

Follow lili Twitter fi http://www.twitter.com/pagalvin