0
 <ItemsControl
        Grid.Row="2"
        ItemsSource="{Binding Caracteristics,UpdateSourceTrigger=PropertyChanged}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel MaxWidth="700"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBox 
                    Text="{Binding Value}"
                    wpf:HintAssist.Hint="{Binding Key}"
                    Style="{DynamicResource MaterialDesignFloatingHintTextBox}"
                    MinWidth="150"
                    MaxWidth="150"
                    Margin="15"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        
    </ItemsControl>

and in the ViewModel

public Dictionary<string,string> Caracteristics { get; set; }

I want to change the strings of the dictionaries from the textbox

this is the full Exception:

InvalidOperationException: A TwoWay or OneWayToSource binding cannot work on the read-only property 'Value' of type 'System.Collections.Generic.KeyValuePair`2[System.String,System.String]'.

  • 2
    `Dictionary` is an `IEnumerable>` where KeyValuePair has a readonly property `public TValue Value { get; }`. You can't edit the dictionary values this way. Bind the ItemsControl to a collection of your own item class with a read/write Value property. – Clemens Jan 12 '22 at 06:41
  • 2
    Also note that `UpdateSourceTrigger=PropertyChanged` on the ItemsSource Binding is pointless. It has no effect at all. – Clemens Jan 12 '22 at 06:53

0 Answers0