使用gridview我有一列具有綁定到基礎對象列表的NumericUpDown控件。問題是我可以綁定到UpUp控件的valuechanged事件,但是當我更新百分比時,它不會在屏幕上更新(GridView)。如果在member.refreshCandidatesGrid我打電話grid.Rebind()它會導致一個混亂(屏幕鎖定)。如果我在側面添加一個按鈕,然後在設置所有值後單擊該按鈕,並使用rebind everythgin正常工作,可以調用member.refreshCandidatesGrid。GridView:用於更新第二列的NumericUpDown列
我很想有1 2的方法是可行的:
推微調(數字沿着上下),並有火(中微調每個時鐘週期)的事件,我可以用它來更新百分率值
有一個事件火,當我離開這個微調場,不幸的是,引發LostFocus看起來是可能是有意義的唯一事件,似乎微調的起訴期間火...
關於方法的思考,代碼結構(即使不相關)都很感激 - 先謝謝您。
的XAML看起來somesthing這樣的:
<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 ;
()
這只是一個記錄清單,沒有什麼特別的... – akaphenom 2010-08-27 13:54:27
這是一個很容易的變化 - 謝謝。 – akaphenom 2010-08-27 15:17:31
讓Inotify無處不在... – akaphenom 2010-09-16 15:40:22