ObservableCollectionsの新機能ですが、動作するはずのコードを作成しました。残念ながらそれはしません。起こっていない唯一のことは、私のGUIが更新されていないことです。私は、値が(デバッガを使ってチェックされた)バックで更新されていることを知っています。SilverlightのUIが更新されない - ObservableCollectionが再インスタンス化される
私は間違っていますか?後ろの私のコードの
<TextBlock Name="tbCallsOpen" Text="{Binding IndicatorValue}" />
これによりサンプル:TextBlockのための私のXAMLのサンプルとここ
public partial class CurrentCalls : UserControl
{
Microsoft.SharePoint.Client.ListItemCollection spListItems;
ObservableCollection<CurrentCallIndicator> CallIndicators = new ObservableCollection<CurrentCallIndicator>();
public CurrentCalls()
{
InitializeComponent();
DispatcherTimer dispatchTimer = new DispatcherTimer();
dispatchTimer.Interval = new TimeSpan(0, 0, 20);
dispatchTimer.Tick += new EventHandler(BindData);
dispatchTimer.Start();
}
private void BindData(object sender, EventArgs args)
{
//splistitems is a sharepoint list. Data is being retrieved succesfully, no issues here.
foreach (var item in spListItems)
{
//My custom class which implements INotifyPropertyChanged
CurrentCallIndicator indicator = new CurrentCallIndicator();
indicator.IndicatorValue = item["MyValueColumn"];
//Adding to ObservableCollection
CallIndicators.Add(indicator);
}
//Setting Datacontext of a normal TextBlock
tbCallsOpen.DataContext = CallIndicators.First(z => z.IndicatorName == "somevalue");
}
}
これで、ObservableCollectionのCollectionChangedイベントにバインドされたことが追加されました。ただし値は更新されますが、コントロールはありません。 – Fox
DispatchTimerなどの不要なコードをすべて削除し、動作するかどうかを確認します。それを絞り込む必要があります。出力ウィンドウを確認することもできます。 –