jamii Archives: XAML

Kuweka Urefu wa ListboxItems Katika listbox programmatically kwa Windows Hifadhi 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. Hadi mwisho huu, Mimi aliongeza listbox kama ifuatavyo:

<Listbox x:Jina ="GameStateLog" HorizontalAlignment ="Kituo cha" Urefu ="221" VerticalAlignment ="Juu" Width ="499" Padding ="0" FontSize ="10">

 

C # kanuni na idadi ya listbox katika Runtime alikuwa pamoja na mistari ya:

GameStateLog.Items.Insert(0, GameStateCounter     + ": Mpya mchezo hali: kusubiri kwa mchezaji 1 jina");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. Kwamba inafanya hisia kama nataka watumiaji wa mwisho na kuwa na uwezo wa kuchagua vitu hivi lakini haina mantiki wakati mimi nataka tu kuonyesha mfululizo mbio ya ujumbe logi - watumiaji si kuchagua hizi, just view them. Ilikuwa ni ajabu vigumu kupata njia rahisi ya kufanya hivyo na arguably, the way I found it isn’t necessarily “easy” but I got it working OK. ufahamu muhimu alikuja kutoka hii posting hapa (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. Badala ya kuongeza masharti ya ukusanyaji Vitu kwenye listbox, add ListBoxItems. Kwa kuongeza string, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. kanuni mpya ni:

        binafsi utupu AddGameStateLogMessage(string theMessage)
        {
            ListBoxItem kwamba = mpya ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Unene thisPadding = mpya Unene(5, 0, 5, 0);
            li.Padding = thisPadding;

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

 

Here I’m creating ListBoxItem’s and inserting them. Mimi kuondolewa padding ziada kwa kuweka unene wake.

Hii ni pretty rahisi kama mimi na nia ya kufanya baadhi ya rangi coding kuonyesha aina fulani ya ujumbe na na moja kwa moja na kuongeza ListBoxItems mimi kupata style yao kwa njia yoyote nataka.

Matumaini hii husaidia mtu!

</mwisho>

undefinedKujiunga na blog yangu.

Kufuata yangu juu ya Twitter kwa http://www.twitter.com/pagalvin