GridView:NumericUpDown列,用于更新第二列

时间:2010-08-26 21:33:20

标签: wpf silverlight f# spinner numericupdown

使用gridview我有一个列,其中NumericUpDown控件绑定到基础对象列表。问题是我可以绑定到UpDown控件上的valuechanged事件,但是当我更新百分比时,它不会在屏幕上更新(GridView)。如果在member.refreshCandidatesGrid中我调用 grid.Rebind(),则会导致混乱(屏幕锁定)。如果我在旁边添加一个按钮并在设置完所有值后单击该按钮并使用rebind everythgin调用member.refreshCandidatesGrid正常工作。

我希望有两种方法中的一种可以工作:

  1. 按下微调器(数值更新),然后触发一个事件(微调器中的每个刻度)我可以用来更新百分比

  2. 当我离开旋转器区域时会发生事件,不幸的是LostFocus看起来是唯一可能有意义的事件,并且似乎在旋转器的起诉期间发射......

  3. 对方法,代码结构(即使不相关)的想法都很感激 - 谢谢你提前。

    XAML看起来像这样:

    <telerik:RadGridView x:Name="candidateGrid" DataContext="{Binding}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Score" IsFilterable="False"
                            DataMemberBinding="{Binding score, Mode=TwoWay}" Width="80" >
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding score}" HorizontalAlignment="Right"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                        <telerik:GridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadNumericUpDown Loaded="Editor_Loaded" Maximum="10000" UpdateValueEvent="PropertyChanged"  IsInteger="True"  Minimum="0" ValueChanged="score_ValueChanged"
                                        Value="{Binding score, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Width="60" O />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Header="Percent" IsReadOnly="True" IsFilterable="False" Width="70">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding percent}" HorizontalAlignment="Right"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
    

    它绑定到f#类,如下所示:

    namespace BV
    
    open System
    open System.Text.RegularExpressions
    open System.Windows ;
    open System.Windows.Controls;
    open System.Windows.Controls.Primitives ;
    open System.Windows.Media ;
    open Telerik.Windows.Controls;
    
    open Globals
    open RpcBV
    
    type Page() as this =    
        inherit UriUserControl("/BV;component/page.xaml", "page")
    
        // instance data
        let mutable brokers = RpcBV.getCandidates()
    
        // bound controls for add candidate
        let FE : FrameworkElement = (this.Content :?> FrameworkElement)
        let candidateGrid : RadGridView = FE ? candidateGrid
    
        do
            firm.ItemsSource <- RpcBV.getFirms()
            email.Background <- SolidColorBrush(Colors.Red)
            addBtn.IsEnabled <- false
            this.refreshCandidatesGrid() ;
    
        member this.refreshCandidatesGrid () =
            candidateGrid.ItemsSource <- brokers ;
            ()
    
    
    
        member this.calculatePercentages() =
            let totalScore = List.fold (fun acc (candidate: ScorableCandidate) -> acc + candidate.score) 0 brokers
    
            let scoreEm (candidate: ScorableCandidate) =
                 candidate.percent <- (float candidate.score) / float totalScore * 100.
    
            List.iter scoreEm <| brokers
    
        member this.addCadidate_Click (sender : obj) (args : RoutedEventArgs)  = 
            this.addCandidateFromForm()
            this.resetAddCandidateForm()
            this.refreshCandidatesGrid()
    
        member this.score_LostFocus (sender : obj) (args : RoutedEventArgs)  = 
            ()
    
        member this.score_ValueChanged (o : obj) (arg : RadRangeBaseValueChangedEventArgs) = 
            this.calculatePercentages()
    
        member this.Editor_Loaded (sender:obj) (args: RoutedEventArgs) =
            let ctrl = sender :?> Control;
            ctrl.Focus() |> ignore ;
            ()
    

1 个答案:

答案 0 :(得分:1)

如果希望在UI中立即反映属性更改,则控件绑定的类型可能应该实现INotifyPropertyChanged接口(或使用其他机制,如公开DependencyProperties)。您对ScorableCandidate的定义是什么样的?