Tag Archives: App Store

Tapaidh agus éasca: Socraigh an Méid na Míreanna i mBosca Liosta i Store App Windows

I App Store Windows Tá mé ag cruthú, Ba mhaith liom a thaispeáint don úsáideoir teachtaireachtaí eolais éagsúla.  Phioc mé listbox mar an uirlis a thaispeáint dó ionas gur féidir leo a scrollú trí iad agus go léir go stuif maith. 

Is iad na teachtaireachtaí eolais amháin, 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:

        príobháideach neamhní AddGameStateLogMessage(teaghrán theMessage)
        {
            TextBox t = nua TextBox();
            t.Text = GameStateCounter   + ": " + theMessage;
            t.TextWrapping = TextWrapping.Wrap;
            t.MinWidth = 400;
            Tiús thisPadding = nua Tiús(5, 0, 5, 0);
            t.Padding = thisPadding;
            t.FontSize = 12;

            ListBoxItem go = nua ListBoxItem();
            li.Content = t;
            li.MaxHeight = 25;
            thisPadding = nua Tiús(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, etc.

Ar Aghaidh, I create a ListBoxItem and set its content to the formatted TextBox.

Mar fhocal scoir, 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.

</deireadh>

undefinedLiostáil le mo bhlag.

Lean mé ar Twitter ag http://www.twitter.com/pagalvin

Socrú an Airde na ListboxItems I listbox programmatically le haghaidh Windows App Store

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. Chun na críche sin, Chuir mé listbox mar seo a leanas:

<Listbox x:Ainmnigh ="GameStateLog" HorizontalAlignment ="Ionad" Airde ="221" VerticalAlignment ="Barr" Width ="499" Stuála ="0" FontSize ="10">

 

An C # cód a populate an listbox ag runtime a bhí cosúil leis na:

GameStateLog.Items.Insert(0, GameStateCounter     + ": Stáit cluiche nua: ag fanacht le imreoir 1 ainm");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added. Sin a dhéanann ciall más mian liom úsáideoirí deiridh a bheith in ann a roghnú na míreanna seo ach ciall a bhaint as nuair is mian liom ach a thaispeáint sraith reáchtáil teachtaireachtaí loga - ní bheidh úsáideoirí a roghnú na, just view them. Bhí sé strangely deacair a fháil ar bhealach éasca é seo a dhéanamh agus arguably, the way I found it isn’t necessarily “easy” but I got it working OK. Tháinig an léargas eochair as an phost anseo (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea. In ionad teaghráin cur leis an mbailiúchán Míreanna ar an listbox, add ListBoxItems. Trí chur ar shraith, the ListBox was creating its own ListBoxItem on its own. I wasn’t able to affect anything about that ListBoxItem after the fact. Tá an cód nua:

        príobháideach neamhní AddGameStateLogMessage(teaghrán theMessage)
        {
            ListBoxItem go = nua ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Tiús thisPadding = nua Tiús(5, 0, 5, 0);
            li.Padding = thisPadding;

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

 

Here I’m creating ListBoxItem’s and inserting them. Bhaint mé an stuáil de bhreis ag leagan síos a tiús.

Tá sé seo go leor solúbtha agus is féidir liom a bhfuil sé ar intinn a dhéanamh ar roinnt dath códú a aird a tharraingt ar chineálacha áirithe teachtaireachtaí agus ag díreach ListBoxItems chur rachaidh mé chun iad a stíl ar bhealach ar bith is mian liom.

Tá súil Cuidíonn seo duine éigin!

</deireadh>

undefinedLiostáil le mo bhlag.

Lean mé ar Twitter ag http://www.twitter.com/pagalvin