タイトルバーにボタンを追加しようとしています。私のXAMLは、次のようになります。Windows 10 Univeral App - タイトルバーのボタンが機能しない
<Page
x:Class="FullScreen.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FullScreen"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="TitleBar">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Application Name" VerticalAlignment="Center"/>
<Button Grid.Column="1" Content="Test" Click="Button_Click"/>
</Grid>
</Grid>
<Grid Grid.Row="1">
<TextBlock>Content</TextBlock>
</Grid>
</Grid>
</Page>
は.csページはこのコードを持っている:
using System;
using Windows.ApplicationModel.Core;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace FullScreen
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(TitleBar);
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await new MessageDialog("Click!").ShowAsync();
}
}
}
ボタンが現れるが、それは、クリックイベントに応答しません。コンストラクタの2行をコメントアウトすると、
public MainPage()
{
InitializeComponent();
//CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
//Window.Current.SetTitleBar(TitleBar);
}
ボタンがアプリケーションの本体にあり、clickイベントが正しく機能します。私は何が欠けていますか?
ありがとう、