开发者

How to create a simple editable dataGrid in Silverlight

I want to bind an 'ObservableCollection' to a Silverlight dataGrid and allow the contents to be editable.

I've got the following XAML, which allows the editing in the UI, but once I click off the row it changes back to the original.

I'm obviously missing something, any ideas?

    <sdk:DataGrid AutoGenerateColumns="False"
                  Height="81"
                  Margin="520,349,60,0"
                  Name="MessageBoxButtons"
                  ItemsSource="{Binding Path=ButtonsView}"
                  AlternatingRowBackground="Gainsboro"
                  RowBackground="White"
                  HeadersVisibility="All"
                  BorderThickness="2"
                  VerticalAlignment="Top"
                  CanUserSortColumns="False">                      
        <sdk:DataGrid.Columns>
     开发者_如何学Go       <sdk:DataGridTextColumn Binding="{Binding}"
                                    CanUserReorder="True"
                                    CanUserResize="True"
                                    CanUserSort="True"
                                    Width="*"
                                    Header="Button Text" />               
        </sdk:DataGrid.Columns>
    </sdk:DataGrid>


Strings are immutable. That is, you cannot change the value of a specific instance of a string. What happens when you assign string values to strings is that a new String object is created and assigned to your variable.

Binding normally works on properties of objects. You are basically treating the string as both a source of data and a property that can be changed. The end result is that the value is changed then thrown away as the actual strings in the list are not replaced.

You want to have a list of simple objects that have string properties instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜