我正在使用一个绑定到我的 ViewModel.SeletedLogItem 属性的内容控件,该属性是 LogItemDTO 类型,在 DataTemplate 的 DataType 中指定。当我将绑定设置为时,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>