0

在这个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 为空,可能默认为透明,这就是我看不到编辑的原因

4

0 回答 0