0

私の XAML では、DataGridTextXolumns を含む DataGrid を定義しました。単純な列はすべてソース (ObservableCollection) を適切に更新しますが、フィールドであるソース フィールドは更新しませんList<string>。XAML で定義するために何が欠けていますか?

<UserControl x:Class="MyTool.MyTabItem"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <DataGrid x:Name="notificationsGrid" ItemsSource="{Binding}" 
                  AlternatingRowBackground="LightBlue" AutoGenerateColumns="False" CanUserAddRows="True" IsReadOnly="False" 
                  SelectionMode="Single" BorderThickness="3" Unloaded="DataGrid_Unloaded" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Op" Binding="{Binding Mode=TwoWay, Path=Notification.Op}">
                    <DataGridTextColumn Header="DetailParams" Binding="{Binding Path=Notification.DetailParams, Mode=TwoWay, 
                                                                    Converter={StaticResource StringListConverter}, UpdateSourceTrigger=LostFocus}"> 
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </ScrollViewer>
    </Grid>
</UserControl>

列「Op」の更新は正常に機能しますが、「DetailParams」は機能しません。

使用される StringToListConverter のコードは次のとおりです。

    public class StringToListConverter : IValueConverter
{
    /// <summary>
    /// Converts a comma separated string into a List<string>.
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if( value is string)
        {
            return value;
        }            

        Console. WriteLine("DetailParams: " + string.Join(",", ((List<string>)value)));
        return string.Join(",", (List<string>)value);
    }

    /// <summary>
    /// Converts a List<string> into a comma separated string.
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Console.WriteLine(string.Join(",", value));
        return string.Join(",", value);
    }
}

UserControl の DataSource は次のように定義されます。

    public partial class RawNotificationTabItem : UserControl//, INotifyPropertyChanged
{
    private ObservableCollection<RawNotificationRowViewModel> _notifications { get; set; }
    //public StringToBoolConverter StringToBoolConverter {
    //    get { return StringToBoolConverter; }
    //    set { StringToBoolConverter = value; }
    //}

    public RawNotificationTabItem(ObservableCollection<RawNotificationRowViewModel> rnvm)
    {
        _notifications = rnvm == null ? _notifications = new ObservableCollection<RawNotificationRowViewModel>() : rnvm;
        this._notifications = rnvm;
        DataContext = _notifications;
        InitializeComponent();
    }
    ...
}
4

1 に答える 1