jamii Archives: Madirisha Hifadhi

Haraka na Easy: Kuweka Ukubwa wa Vitu katika a Orodha katika Windows Hifadhi App

Katika Hifadhi App Windows mimi nina kujenga, Nataka kuonyesha user mbalimbali ujumbe habari.  Mimi ilichukua listbox kama chombo cha kuonyesha kuwa ili waweze kitabu kupitia wao na mambo ambayo yote mema. 

ujumbe ni habari tu, hivyo hakuna haja ya kutoa whitespace kwamba wote ziada karibu yao tangu mtumiaji anaweza kamwe kuchagua yao kwa ajili ya kitu chochote.  tabia default ya listbox hutoa kiasi kikubwa cha padding na nilitaka kujikwamua ni.  Vizuri .... huwezi kufanya aina ya kitu juu ya listbox moja kwa moja.  ISIPOKUWA, unaweza kufanya hivyo kwa vitu wewe kuongeza:

        binafsi utupu AddGameStateLogMessage(string theMessage)
        {
            Kisanduku cha maandishi t = mpya Kisanduku cha maandishi();
            t.Text = GameStateCounter     + ": " + theMessage;
            t.TextWrapping = TextWrapping.Wrap;
            t.MinWidth = 400;
            Unene thisPadding = mpya Unene(5, 0, 5, 0);
            t.Padding = thisPadding;
            t.FontSize = 12;

            ListBoxItem kwamba = mpya ListBoxItem();
            li.Content = t;
            li.MaxHeight = 25;
            thisPadding = mpya Unene(5, 0, 5, 0);
            li.Padding = thisPadding;

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

katika hapo juu, Mimi kujenga kisanduku cha maandishi na kuweka font yake, yake padding, nk.

Ijayo, Mimi kujenga ListBoxItem na kuweka maudhui yake ya kisanduku cha maandishi mpangilio.

Hatimaye, Mimi kuingiza ListBoxItem katika listbox.  (Nataka kuonyesha ujumbe wa hivi karibuni juu ya orodha, hivyo Insert(0,li) badala ya kuongeza rahisi() sala.).

Mimi nitakuwa tweaking hii kidogo kabla ya Najisikia furaha sana na tabia listbox lakini muundo inavyoonekana hapo juu imekuwa sana matunda.  Hopefully mtu mwingine anaona ni manufaa.

</mwisho>

undefinedKujiunga na blog yangu.

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

Haraka na Easy: Hoja ya Mstatili Kutumia C # Katika Windows Hifadhi App

Blog yangu falsafa ya jumla ni kwamba ni kikamilifu faini ya blog juu ya zamani, makazi masomo ambayo wamekuwa kufunikwa kwa kifo mahali pengine.  Mimi kudhani mada hii ni mmoja wa wale, lakini nina mabalozi ni anyway.

Nimekuwa kazi juu ya programu ya kuhifadhi dirisha na mimi nina katika sehemu ambapo mimi haja ya kufanya baadhi changamfu.  Hadi mwisho huu, 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.

Katika hatua nyingine, 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).

</mwisho>

undefinedKujiunga na blog yangu.

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

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