kategorie Argief: Windows Store

Vinnige en maklike: Stel die grootte van 'n Items in 'n lys Box in 'n Windows Store App

In 'n Windows Store App ek skep, Ek wil die gebruiker verskeie inligting boodskappe te wys.  Ek pluk 'n ListBox as die instrument om dit te wys, sodat hulle kan blaai deur hulle en almal wat goeie dinge. 

Die boodskappe is die inligting net, 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:

        private nietig AddGameStateLogMessage(string theMessage)
        {
            TextBox t = nuwe TextBox();
            t.Text = GameStateCounter   + ": " + theMessage;
            t.TextWrapping = TextWrapping.Wrap;
            t.MinWidth = 400;
            Dik thisPadding = nuwe Dikte(5, 0, 5, 0);
            t.Padding = thisPadding;
            t.FontSize = 12;

            ListBoxItem dat = nuwe ListBoxItem();
            li.Content = t;
            li.MaxHeight = 25;
            thisPadding = nuwe Dikte(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, ens..

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

Ten slotte, 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.

</einde>

undefinedSkryf in op my blog.

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

Vinnige en maklike: Skuif na 'n Reghoek met C # In 'n Windows Store App

My algehele blog filosofie is dat dit heeltemal fyn te blog oor ou, vereffen vakke wat tot die dood gedek elders.  Ek neem aan hierdie onderwerp is een van daardie, maar ek blog dit in elk geval.

Ek werk op 'n venster winkel artikels en ek is by die deel waar ek moet 'n paar anima te doen.  Vir hierdie doel, I’ve been figuring out bits and pieces of windows store app animation which, as it turns out, is quite close to, but not exactly like, XAML based animations in .NET (I’m still coming to grips with the fact that WinRT <> .NET 🙂 ).

This morning I wanted to get a handle on drag and drop operations.  En route to that, I got bogged down moving a rectangle instead :).  Here’s the code that moves a rectangle when the user clicks a button:

   1:   
   2:              MatrixTransform ct = (MatrixTransform)rectBig.RenderTransform;
   3:              Matrix m = ct.Matrix;
   4:              m.OffsetX  = 10;
   5:              m.OffsetY  = 10;
   6:              ct.Matrix = m;
   7:              rectBig.RenderTransform = ct;

The trick here is that I can’t directly change OffsetX or OffsetY.  There may be a more clever way of doing this (and if you know and feel like, please post in the comments). 

In order to do this, I need to:

1. Get the MatrixTransform of the rectangle (by casting RenderTransform).

2. Get the Matrix of that guy.

3. Change the Matrix’s offsets.

4. Reassign the Matrix back to the MatrixTransform.

5. Reassign the MatrixTransform back to the Rectangle.

To test it, I put a rectangle and button the screen. When I click the button, the above logic executes and moves the rectangle immediately.

Op 'n sekere punt, I’d like to animate this but I have no idea how to get a DoubleAnimation to work on it (Storyboard.SetTargetProperty() is a mystery to me on this for the time being).

</einde>

undefinedSkryf in op my blog.

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

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