ViewModel.SeletedLogItem プロパティにバインドされたコンテンツ コントロールを使用しています。このプロパティは、DataTemplate の DataType で指定された LogItemDTO タイプです。バインディングを に設定するMode=TwoWay
と、コンバーターが必要だというコンパイル エラーが発生します。
無効なバインディング パス 'ViewModel.SelectedLogItem': コンバーターなしでタイプ 'LifeLog.Data.DomainEntities.LogItemDTO' を 'System.Object' にバインドできません
以下は、ビューモデルの一部とコンテンツ コントロールの xaml です。
public class LogItemEditPageViewModel : LifeLog.App.Mvvm.ViewModelBase
{
#region Properties
private LogItemInfo OriginalData { get; set;}
private LogItemDTO selectedLogItem;
public LogItemDTO SelectedLogItem { get { return selectedLogItem; } set { Set(ref selectedLogItem, value); } }
<ContentControl Margin="20,0,0,0" Grid.Row="2" Grid.Column="0" Content="{x:Bind ViewModel.SelectedLogItem, Mode=TwoWay}">
<ContentControl.ContentTemplate>
<DataTemplate x:DataType="dat:LogItemDTO">
<StackPanel>
<TextBox Text="{x:Bind Log, Mode=TwoWay}" FontSize="15" Height="450" Width="728"
TextWrapping="Wrap"
AcceptsReturn="True"
Foreground="{StaticResource Yell}" Background="{StaticResource DGreen}"
/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" Margin="0,10, 10,10" >
<TextBlock Text="LastUpdated:" Margin="0,0,5,0" />
<TextBlock Text="{x:Bind LastUpdated}" Foreground="{StaticResource DGreen}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10" >
<TextBlock Text="Date Added:" Margin="0,0,5,0" />
<TextBlock Text="{x:Bind DateAdded}" Foreground="{StaticResource DGreen}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>