root/platform/silverlight/eLearn/trunk/eLearn/Page.xaml.cs @ 14610

Revision 14610, 3.4 kB (checked in by coma2n, 5 years ago)

platform/silverlight/eLearn/trunk: initial import

Line 
1#region license
2/*
3Copyright (c) 2008, Kouji Yamaguchi
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
8* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
12* Neither the name of coma2n nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13
14THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
17OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
18OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20*/
21#endregion
22
23#region namespaces
24
25using System;
26using System.Windows;
27using System.Windows.Browser;
28using System.Windows.Controls;
29
30#endregion
31
32namespace eLearn {
33    /// <summary>
34    /// メインページ
35    /// </summary>
36    public partial class Page : UserControl {
37
38        #region fields
39
40        private StudyManager studyMgr;
41
42        #endregion
43
44        #region properties
45
46        /// <summary>
47        /// ルートURLを取得、設定します。
48        /// </summary>
49        private string RootUrl {
50            get;
51            set;
52        }
53
54        #endregion
55
56        #region constructors
57
58        /// <summary>
59        /// 標準的なコンストラクタ
60        /// </summary>
61        public Page() {
62            InitializeComponent();
63
64            var rootUrl = HtmlPage.Document.DocumentUri.ToString();
65
66            for(var i = 0; i < 2; i++) {
67                var pos = rootUrl.LastIndexOf('/');
68                // ケツから/までのURLを取得する。
69                // http://localhost:1100/Home/Index.aspx
70                // ↑どちらの場合でも欲しいのは「http://localhost:1100/」
71                if(pos != -1) rootUrl = rootUrl.Substring(0, pos);
72            }
73            RootUrl = rootUrl + "/";
74
75            studyMgr = new StudyManager(RootUrl);
76            studyMgr.GetStudies(studies => studyList.ItemsSource = studies);
77        }
78
79        #endregion
80
81        private void HyperlinkButton_Click(object sender, RoutedEventArgs e) {
82            var study = ((HyperlinkButton)sender).Tag as Study;
83
84            HtmlPage.Window.Navigate(
85                new Uri(RootUrl + string.Format("Home/Index.aspx?mode=1&id={0}", study.Id))
86            );
87        }
88
89        private void studyList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
90            editButton.IsEnabled = remButton.IsEnabled = e.AddedItems.Count > 0;
91        }
92
93    }
94}
Note: See TracBrowser for help on using the browser.