0

使用网格视图,我有一列将 NumericUpDown 控件绑定到底层对象列表。问题是我可以绑定到 UpDown 控件上的 valuechanged 事件,但是当我更新百分比时,它不会在屏幕上更新(GridView)。如果在 member.refreshCandidatesGrid 我调用grid.Rebind()它会导致混乱(屏幕锁定)。如果我在侧面添加一个按钮并在设置所有值并使用重新绑定 allthgin 调用 member.refreshCandidatesGrid 后单击该按钮,则可以正常工作。

我希望有 2 种方法中的 1 种起作用:

  1. 推动微调器(数字向上),并让它触发一个事件(微调器中的每个刻度),我可以用它来更新百分比

  2. 当我离开那个微调器字段时发生事件,不幸的是,LostFocus 看起来是唯一可能有意义的事件,并且似乎在微调器起诉期间触发......

对方法、代码结构(即使不相关)的想法都值得赞赏 - 在此先感谢您。

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 ;
        ()
4

1 回答 1

1

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

于 2010-08-27T08:50:19.357 回答