基於我能從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是公開的。我該怎麼辦?
in SetAndSaveSectionNames should not the call be hubPageSettingsFlyout.popupSectionName.IsOpen = true? –
當我替換它時: TimeAndSpaceLines.View.TSLsSettings.popupSectionName.IsOpen = true; 與此: hubPageSettingsFlyout.popupSectionName.IsOpen = true; ...我得到了'''TimeAndSpaceLines.View.TSLsSettings。popupSectionName」不可訪問由於其保護級別」 中的XAML hubPageSettingsFlyout的聲明是: 所以我仍然困惑我可能已經得到了它。都錯了;我必須退後一步,並重新開始 –