Mjesečni arhiv: Travanj 2013

Brzo i jednostavno: Premještanje pravokutnik pomoću C # u Windows Store App

Moj ukupni blog filozofija je da je savršeno u redu blog o stara, naselili teme koje su pokrivene na smrt negdje drugdje.  Pretpostavljam da je ova tema je jedna od onih, ali ja sam ga svejedno bloganje.

Radio sam na app store prozor, a ja sam na dijelu gdje trebam napraviti neke animiranje.  U tom cilju, 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 <> .NETO 🙂 ).

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.

U nekom trenutku, 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).

</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