2012-11-02 46 views
0

基於我能從Freeman的書「Metro Revealed」中收集到的信息(其中BTW是目前爲止最好的,儘管重量不到100頁),我試圖實現一個設置彈出窗口(popup )。我如何參考我的彈出窗口?

我有這樣的相關代碼:

有用戶控件/是彈出:

<UserControl 
    x:Class="TimeAndSpaceLines.View.TSLsSettings" 
    . . . 
    <Popup x:Name="popupSectionName" IsLightDismissEnabled="True" > 
    . . . 
    </Popup> 
</UserControl> 

「主」 頁面的XAML:

<common:LayoutAwarePage 
    x:Name="pageRoot" 
    . . . 
    xmlns:settingsflyout="using:TimeAndSpaceLines.View" 
    . . . 
     </Grid> 
     <settingsflyout:TSLsSettings x:Name="hubPageSettingsFlyout"/> 
     <VisualStateManager.VisualStateGroups> 
    . . . 

「主「頁面的相關」代碼隱藏「:

public ItemsPage() 
{ 
    InitializeComponent(); 
    SettingsPane.GetForCurrentView().CommandsRequested += OnSettingsPaneCommandRequested; 
} 

private void OnSettingsPaneCommandRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) 
{ 
    // Add the commands one by one to the settings panel 
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection1Name", 
                  "Change the name of Section 1", SetAndSaveSectionNames)); 
. . .   
} 

然而,當我嘗試打開它這種方式:

private void SetAndSaveSectionNames(IUICommand command) 
{ 
    TimeAndSpaceLines.View.TSLsSettings.popupSectionName.IsOpen = true; 
    . . . 
} 

我笑臉相迎:

An object reference is required for the non-static field, method, or property 
'TimeAndSpaceLines.View.TSLsSettings.popupSectionName' 

和:

'TimeAndSpaceLines.View.TSLsSettings.popupSectionName' is inaccessible due to its protection level 

然而popupSectionName不是一個階級,而是它所在的階級s是公開的。我該怎麼辦?

+0

in SetAndSaveSectionNames should not the call be hubPageSettingsFlyout.popupSectionName.IsOpen = true? –

+0

當我替換它時: TimeAndSpaceLines.View.TSLsSettings.popupSectionName.IsOpen = true; 與此: hubPageSettingsFlyout.popupSectionName.IsOpen = true; ...我得到了'''TimeAndSpaceLines.View.TSLsSettings。popupSectionName」不可訪問由於其保護級別」 中的XAML hubPageSettingsFlyout的聲明是: 所以我仍然困惑我可能已經得到了它。都錯了;我必須退後一步,並重新開始 –

回答

1

從 「主」 頁面的相關 「代碼隱藏」 試試這個!

2

TimeAndSpaceLines.View.TSLsSettings是一個類名,而不是實例名。你想要的是實例的名稱:hubPageSettingsFlyout。我建議在你的popupSectionNameIsLightDismissEnabled上使用綁定,所以你不必嘗試找到UI元素,而只是檢查它綁定到的任何屬性的值。

1

它做了一點不同

,而不是創建一個UserControl,我剛剛創建了一個BasicPage,然後從我的主要頁面創建的頁面的一個實例(見下文var mypane = new CreateProvider {Height = Window.Current.Bounds.Height};),其中CreateProviderXAML頁面,我通過我的Popup_providerPopup.Child = mypane;。試試這種方式,我認爲你的UserControl也可以正常工作。只需將您的用戶控制分配到Popup,如_popup.Child = popupSectionName;

var myPopUp = (PopUp)hubPageSettingsFlyout.FindName("popupSectionName"); 

這將作品:

 // Create a Popup window which will contain our flyout. 
     _providerPopup = new Popup 
          { 
           Height = Window.Current.Bounds.Height, 
           ChildTransitions = new TransitionCollection 
                 { 
                  new PaneThemeTransition 
                   { 
                    Edge = 
                     (SettingsPane.Edge == 
                     SettingsEdgeLocation.Right) 
                      ? EdgeTransitionLocation.Right 
                      : EdgeTransitionLocation.Left 
                   } 
                 } 
          }; 

     // Add the proper animation for the panel. 

     // Create a SettingsFlyout the same dimenssions as the Popup. 
     var mypane = new CreateProvider {Height = Window.Current.Bounds.Height}; 

     // Place the SettingsFlyout inside our Popup window. 
     _providerPopup.Child = mypane; 

     // Let's define the location of our Popup. 
     _providerPopup.SetValue(Canvas.LeftProperty, 
           SettingsPane.Edge == SettingsEdgeLocation.Right 
            ? (Window.Current.Bounds.Width - SettingsWidth) 
            : 0); 
     _providerPopup.SetValue(Canvas.TopProperty, 0); 
     _providerPopup.IsOpen = true; 
+0

我相信我做的是: 私人無效OnSettingsPaneCommandRequested(SettingsPane發件人,SettingsPaneCommandsRequestedEventArgs參數) { SettingsCommand CMD =新SettingsCommand(「樣本」。 「Sound Options」,(x)=> {設置Popup = new Popup(); ... var settingsPane = new TSLsSettings(); 。 。 。 _settingsPopup.Child = settingsPane; _settingsPopup.IsOpen = true; }); args.Request.ApplicationCommands.Add(cmd); } –

相關問題