Silverlight数据网格单元格编辑不会反映在单元格中

时间:2013-08-01 13:15:44

标签: silverlight data-binding datagrid cell edit

在这个silverlight网格单元格中,当编辑值更新时,显示值不会更新,为什么会有任何想法?

<sdk:DataGridTemplateColumn Header="Bid Qty" IsReadOnly="True">
    <sdk:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock VerticalAlignment="Center" 
                       HorizontalAlignment="Center" 
                       Text="{Binding Path=BidPrice.Quantity, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource CustomDoubleToStringConverter}}" 
                       Foreground="{Binding Path=BidPrice.TextColour}" 
                       ToolTipService.ToolTip="{Binding Path=BidPrice.ToolTip}" 
                       ToolTipService.Placement="Right" />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellTemplate>
    <sdk:DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Path=BidPrice.Quantity, Mode=TwoWay, Converter={StaticResource CustomDoubleToStringConverter}}" />
        </DataTemplate>
    </sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>

代码(非常简化):

// field is bound to BidPrice on this
    public class PriceStackLine : INotifyPropertyChanged
    { 
        public ProductPrice BidPrice { get; set; }
    }

// BidPrice is a ProductPrice with a Quantity property
    public class ProductPrice : INotifyPropertyChanged
    {
            private double _qty;
            public double Quantity
            {
                get
                {
                    return _qty;
                }
                set
                {
                    _qty = value;
                    NotifyPropertyChanged("Quantity");
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;
            public void NotifyPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }


// converter
    public class CustomDoubleToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double num = (double)value;

            if (num == 0)
                return string.Empty;

            return num;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double result = 0;
            double.TryParse(value.ToString(), out result);
            return result;
        }
    }

更新 - 已修复!新编辑的TextColour为空,可能默认为透明,这就是为什么我看不到编辑

0 个答案:

没有答案