Arhiva oznaka: Windows Store

Brzo i jednostavno: Postavite veličinu stavki u okviru popisa u Windows Store App

U App Store Windows Izrađujem, Želim pokazati korisničke razne informativne poruke.  Ja pokupila listbox kao alat za to pokazati, tako da oni mogu pomicati kroz njih i sve to dobre stvari. 

Poruke su samo informacijski, so there’s no need to provide all that extra whitespace around them since the user can never select them for anything.  The default behavior of the ListBox provides a substantial amount of padding and I wanted to get rid of it.  Well …. you can’t do that sort of thing on the ListBox directly.  HOWEVER, you can do it to the items you add:

        privatni poništiti AddGameStateLogMessage(niz theMessage)
        {
            TextBox t = novi TextBox();
            t.Text = GameStateCounter   + ": " + theMessage;
            t.TextWrapping = TextWrapping.Wrap;
            t.MinWidth = 400;
            Debljina thisPadding = novi Debljina(5, 0, 5, 0);
            t.Padding = thisPadding;
            t.FontSize = 12;

            ListBoxItem da = novi ListBoxItem();
            li.Content = t;
            li.MaxHeight = 25;
            thisPadding = novi Debljina(5, 0, 5, 0);
            li.Padding = thisPadding;

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

in the above, I’m creating a TextBox and setting its font, its padding, itd..

Sljedeći, I create a ListBoxItem and set its content to the formatted TextBox.

Konačno, I insert the ListBoxItem into the ListBox.  (I want to show most recent messages at the top of the list, hence the Insert(0,Li) instead of a simple Add() invocation.).

I will be tweaking this a bit before I’m really happy with the ListBox behavior but the pattern shown above has been very fruitful.  Hopefully someone else finds it helpful.

</kraj>

undefinedPretplatite se na moj blog.

Slijedite me na Twitter-u http://www.twitter.com/pagalvin

Postavljanje visinu ListboxItems u listbox Programski za 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. U tom cilju, I dodao listbox kako slijedi:

<Listbox x:Ime ="GameStateLog" HorizontalAlignment ="Centar" Visina ="221" VerticalAlignment ="Vrh" Širina ="499" Podstava ="0" Fontsize ="10">

 

Kod C # naseliti listbox vrijeme izvođenja bio na tragu:

GameStateLog.Items.Insert(0, GameStateCounter     + ": Nova igra državna: čekaju igrača 1 ime");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. To ima smisla ako želim krajnji korisnici moći odabrati te stavke, ali nema smisla kad samo želim pokazati trčanje niz log poruka - Korisnici neće odabirete, just view them. Bilo je neobično teško pronaći jednostavan način da to učinite i nedvojbeno, the way I found it isn’t necessarily “easy” but I got it working OK. Ključni uvid došao iz ove objave ovdje (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. Umjesto dodavanja žice na stavke kolekcije na listbox, add ListBoxItems. Dodavanjem string, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. Novi broj je:

        privatni poništiti AddGameStateLogMessage(niz theMessage)
        {
            ListBoxItem da = novi ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Debljina thisPadding = novi Debljina(5, 0, 5, 0);
            li.Padding = thisPadding;

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

 

Here I’m creating ListBoxItem’s and inserting them. Ja uklonio višak padding postavljanjem njegove debljine.

To je prilično fleksibilan što ne namjeravam napraviti neki bojom istaknuti određene vrste poruka i izravno dodavanjem ListBoxItems sam se na ime bilo koji način im želim.

Nadam se ovo pomaže netko!

</kraj>

undefinedPretplatite se na moj blog.

Slijedite me na Twitter-u http://www.twitter.com/pagalvin