• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 55  文章 - 15  trackbacks - 0
            <2012年10月>
            30123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

                     前文再續(xù),本章介紹如何創(chuàng)建一個(gè)C++版本的Variable Sized Gridview,這里有兩種方法,一種是用微軟的Template,還有另一種方法,簡單些。本章先介紹微軟的方法。
                     其實(shí)C#版本微軟已經(jīng)實(shí)現(xiàn)了,大家可以在VS2012上面去找找,方法是:新建-〉Online-〉Templates-〉Visual C#,右邊選項(xiàng)欄里面就有這個(gè)Variable Sized Grid Template了,創(chuàng)建之后,部署,運(yùn)行,你就可以得到一個(gè)類似于Windows Store 的Ui,下面看兩張圖吧,我們講究有圖有真相。

             1. 找到這個(gè)Template:




            2. 運(yùn)行效果:



                  這個(gè)Template中的代碼我感覺有點(diǎn)繞圈圈,不知道它為什么這么做,但是可以實(shí)現(xiàn)這種效果,我會(huì)試著來講解一下代碼的具體意思。
                  先把代碼帖出來:
             1 public ref class VariableGridView sealed : public Windows::UI::Xaml::Controls::GridView
             2         {
             3         public:
             4             property  Platform::String^ ItemRowSpanPropertyPath
             5             {
             6                 Platform::String^ get()
             7                 {
             8                     return safe_cast<Platform::String^>(GetValue(ItemRowSpanPropertyPathProperty));
             9                 }
            10                 void set(Platform::String^ value)
            11                 {
            12                     SetValue(ItemRowSpanPropertyPathProperty, value);
            13                 }
            14             }
            15             static property Windows::UI::Xaml::DependencyProperty^ ItemRowSpanPropertyPathProperty
            16             {
            17                 Windows::UI::Xaml::DependencyProperty^ get();
            18             }
            19 
            20 
            21 
            22             property  Platform::String^ ItemColSpanPropertyPath
            23             {
            24                 Platform::String^ get()
            25                 {
            26                     return safe_cast<Platform::String^>(GetValue(ItemColSpanPropertyPathProperty));
            27                 }
            28                 void set(Platform::String^ value)
            29                 {
            30                     SetValue(ItemColSpanPropertyPathProperty, value);
            31                 }
            32             }
            33             static property Windows::UI::Xaml::DependencyProperty^ ItemColSpanPropertyPathProperty
            34             {
            35                 Windows::UI::Xaml::DependencyProperty^ get();
            36             }
            37         protected:
            38             virtual void PrepareContainerForItemOverride(Windows::UI::Xaml::DependencyObject^ element, Platform::Object^ item) override;
            39         private:
            40             static Windows::UI::Xaml::DependencyProperty^ _itemRowSpanPropertyPathProperty;
            41             static Windows::UI::Xaml::DependencyProperty^ _itemColSpanPropertyPathProperty;
            42 
            43         };

            這里有幾個(gè)概念,今天先說一下Dependecy Property 這個(gè)東西吧,其他的下次繼續(xù):
                  1. 我現(xiàn)在接觸到的Dependency Property,就是依賴屬性,主要用來進(jìn)行數(shù)據(jù)綁定。我們知道WinRT一個(gè)比較重要的功能就是數(shù)據(jù)的綁定,而綁定的目標(biāo)(target)屬性必須為依賴屬性屬性,而源(source)則沒有要求,你可以是依賴屬性,也可以不是依賴屬性。這部分內(nèi)容我在MVVM那一張已經(jīng)翻譯過了。源和目標(biāo)都是依賴屬性的好處是,在binding的時(shí)候WinRT會(huì)自動(dòng)地幫你做一些事情,這樣源屬性改變,目標(biāo)屬性會(huì)立即改變。如果源屬性不是依賴屬性,那么,包含該屬性的類必須實(shí)現(xiàn) INotifyPropertyChanged 這個(gè)借口,不然,就不行了。
                  2. 依賴屬性的定義有一套的流程。首先,我們看代碼中,在私有域:需要有一個(gè)靜態(tài)的DependencyProperty 變量,在公共域:需要一個(gè)對(duì)應(yīng)的靜態(tài)DependencyProperty屬性。注意,一個(gè)是變量,一個(gè)是屬性,公共域的要有一個(gè)Property關(guān)鍵字。私有域的這個(gè)變量作為公共域?qū)傩缘腷ack store。
                      另外,為了方便存取,還需要一個(gè)額外的屬性來獲得這個(gè)依賴屬性。注意到:DependecyProperty 屬性只有g(shù)et()方法,相關(guān)屬性的set()、get()方法中分別調(diào)用SetValue(),GetValue(),方法。
                     頭文件中就需要這些東西,還沒有結(jié)束,聲明完依賴屬性,我們還需要注冊,讓W(xué)inRT這個(gè)綁定系統(tǒng)知道有這么一個(gè)類,有這樣一個(gè)依賴屬性。注冊的代碼如下:
            1 DependencyProperty^ VariableGridView::_itemColSpanPropertyPathProperty = 
            2     DependencyProperty::Register("ItemColSpanPropertyPath", TypeName(String::typeid), TypeName(VariableGridView::typeid),
            3     ref new PropertyMetadata(nullptr));
                     注冊完,這個(gè)類就有了一個(gè)依賴屬性了。
                    不錯(cuò),現(xiàn)在我們實(shí)現(xiàn)了這個(gè)類的一半了,為了達(dá)到可變尺寸的GridView,還有另一個(gè)重載方法是必不可少的。不過我打算明天再跟大家分享了,今天要早點(diǎn)回家做飯啦。哈哈。先把代碼貼上,C++的代碼跟C#很類似,
               
             1 void VariableGridView::PrepareContainerForItemOverride(DependencyObject^ element, Platform::Object^ item)
             2 {
             3     GridView::PrepareContainerForItemOverride(element, item);
             4     auto viewMode = (Data::DataItem^)(item);
             5     UIElement^ uiElement = safe_cast<UIElement^>(element);
             6 
             7     Binding^ colBinding = ref new Binding();
             8     colBinding->Source = viewMode;
             9     colBinding->Path = ref new PropertyPath(this->ItemColSpanPropertyPath);
            10     BindingOperations::SetBinding(uiElement,VariableSizedWrapGrid::ColumnSpanProperty, colBinding);
            11     
            12 
            13     Binding^ rowBinding = ref new Binding();
            14     rowBinding->Source = viewMode;
            15     rowBinding->Path = ref new PropertyPath(this->ItemRowSpanPropertyPath);
            16     BindingOperations::SetBinding(uiElement,VariableSizedWrapGrid::RowSpanProperty, rowBinding);    
            17 }
                  

            下期預(yù)告:即使完成了上面的兩步,其實(shí)還沒有完全實(shí)現(xiàn)VariableSized GridView,還需要在XAML文件中進(jìn)行相應(yīng)的修改,下期將介紹其余的部分。
            posted on 2012-10-12 17:19 Dino-Tech 閱讀(1321) 評(píng)論(1)  編輯 收藏 引用

            FeedBack:
            # re: Window 8 學(xué)習(xí)筆記(三)-- 如何創(chuàng)建一個(gè)可變尺寸的GridView  2013-09-23 16:35 墮落1990
            樓主能提供完整的源碼么,想系統(tǒng)學(xué)習(xí)下,謝謝啦,  回復(fù)  更多評(píng)論
              

            只有注冊用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久夜色tv网站| 免费一级欧美大片久久网| 噜噜噜色噜噜噜久久| 成人综合久久精品色婷婷| 一本色道久久综合| 久久亚洲私人国产精品| 国产精品久久久久影视不卡| 激情五月综合综合久久69| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 精品无码久久久久久久动漫| 亚洲欧美成人久久综合中文网| 国内精品综合久久久40p| 狠狠干狠狠久久| 性欧美大战久久久久久久久| 精品久久久无码中文字幕天天| 亚洲精品国精品久久99热一| 国产精品伊人久久伊人电影| 久久久久无码精品国产不卡| 伊人久久大香线蕉精品| 欧美熟妇另类久久久久久不卡 | www亚洲欲色成人久久精品| 久久91精品国产91| 国产高潮久久免费观看| 狠狠久久亚洲欧美专区| 午夜精品久久久久久毛片| 亚洲国产天堂久久综合| 伊人久久综在合线亚洲2019| 久久久久女人精品毛片| 国内精品久久久久影院薰衣草| 久久伊人五月天论坛| 久久99精品久久久久久噜噜| 粉嫩小泬无遮挡久久久久久| 亚洲精品美女久久777777| 国内精品综合久久久40p| 久久精品国产清自在天天线 | 精品999久久久久久中文字幕| 国产一区二区久久久| 久久免费视频6| 日韩va亚洲va欧美va久久| 久久强奷乱码老熟女| 综合久久一区二区三区 |