1

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>

4

1 に答える 1

0

コンバーターでバインドできますが、コンバーターを作成する必要があります

何かのようなもの:

public class XConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter)
            {//return converted value
                return (
             //do something here                
               }
        }

次にバインディング

<TextBox  Converter={StaticResource XConverter}></TextBox>
于 2016-06-27T08:16:56.370 に答える