Created
November 28, 2015 03:11
-
-
Save pierre3/9a82de19279b2b9a886a to your computer and use it in GitHub Desktop.
ContentDialog のイベントをx:Bindすると Xaml内部エラーになる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ContentDialog | |
x:Class="RssReaderApp.Views.AddFeedDialog" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:RssReaderApp.Views" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
mc:Ignorable="d" | |
Title="Feedの追加" | |
PrimaryButtonText="追加" | |
SecondaryButtonText="キャンセル" | |
PrimaryButtonCommand="{x:Bind ViewModel.AddFeedCommand}"> | |
<!-- ↑コマンドにx:BindならOK --> | |
<!-- これも普通にOK (コードビハインドのメソッドを普通に指定) | |
PrimaryButtonClick="ContentDialog_PrimaryButtonClick" | |
--> | |
<!-- イベントハンドラをx:Bindすると Xaml内部エラー WMC9999 | |
PrimaryButtonClick="{x:Bind ViewModel.AddFeed}" | |
PrimaryButtonClick="{x:Bind ContentDialog_PrimaryButtonClick}" | |
--> | |
<Grid> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="Auto"/> | |
<RowDefinition Height="Auto"/> | |
<RowDefinition Height="Auto"/> | |
</Grid.RowDefinitions> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="Auto"/> | |
<ColumnDefinition Width="*"/> | |
</Grid.ColumnDefinitions> | |
<TextBlock Grid.Row="0" Grid.Column="0" Text="タイトル" | |
Style="{StaticResource CaptionTextBlockStyle}" | |
VerticalAlignment="Center"/> | |
<TextBox Grid.Row="0" Grid.Column="1" Margin="4" | |
Text="{x:Bind ViewModel.Title,Mode=TwoWay}" /> | |
<TextBlock Grid.Row="1" Grid.Column="0" Text="URL" | |
Style="{StaticResource CaptionTextBlockStyle}" | |
VerticalAlignment="Center" /> | |
<TextBox Grid.Row="1" Grid.Column="1" Margin="4" | |
Text="{x:Bind ViewModel.FeedUrl,Mode=TwoWay}"/> | |
<!-- これはOK --> | |
<Button Grid.Column="1" Grid.Row="2" HorizontalAlignment="Center" | |
Click="{x:Bind ViewModel.AddFeed}">OK</Button> | |
</Grid> | |
</ContentDialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using RssReaderApp.ViewModels; | |
using Windows.UI.Xaml.Controls; | |
namespace RssReaderApp.Views | |
{ | |
public sealed partial class AddFeedDialog : ContentDialog | |
{ | |
AddFeedDialogViewModel ViewModel { get; } = new AddFeedDialogViewModel(); | |
public AddFeedDialog() | |
{ | |
this.InitializeComponent(); | |
} | |
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) | |
{ | |
ViewModel.AddFeed(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Prism.Windows.Mvvm; | |
using RssReaderApp.Models; | |
namespace RssReaderApp.ViewModels | |
{ | |
public class AddFeedDialogViewModel:ViewModelBase | |
{ | |
private RssReaderContext Model = RssReaderContext.Instance; | |
public Prism.Commands.DelegateCommand AddFeedCommand { get; } | |
public string Title { | |
get { return Model.FeedManager.InputFeed.Title; } | |
set { Model.FeedManager.InputFeed.Title = value; } | |
} | |
public string FeedUrl | |
{ | |
get { return Model.FeedManager.InputFeed.FeedUrl; } | |
set { Model.FeedManager.InputFeed.FeedUrl = value; } | |
} | |
public AddFeedDialogViewModel() | |
{ | |
Model.FeedManager.ResetInputFeed(); | |
AddFeedCommand = new Prism.Commands.DelegateCommand(AddFeed); | |
} | |
public void AddFeed() | |
{ | |
Model.FeedManager.TrySetInputFeed(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ContentDialog のイベントをコンパイル時バインディングすると、コンパイル時に以下のエラーが出ます
1>C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\8.2\Microsoft.Windows.UI.Xaml.Common.targets(263,5): Xaml 内部エラー error WMC9999: オブジェクト参照がオブジェクト インスタンスに設定されていません。
(環境)
Microsoft Visual Studio Enterprise 2015
Version 14.0.23107.0 D14REL
ターゲットバージョン Windows 10 (10.0;ビルド10240)