开发者

Microsoft Silverlight DataGrid custom ToolTip

I have SL3 DataGrid and need a tooltip on rows and different columns which has data that needs to be fetched from DataBase when user hovers over the tooltip.

I saw samples around that helps use the current binding context or the static content for the tooltip.

But, how can I get a usercontrol shown in the tooltip which goes and fetches Database only when user brings up the tooltip Also, is there a way to easily fit this into MVVM instead of having a lot of co开发者_如何学JAVAde on the code behind?


I don't think tooltips properly leverage databinding, or at least in the way I think is proper. If you are binding to a ViewModel property in your XAML tool tip declaration that is going to resolve immediately, which means the call will be made immediately. I suppose you could plumb in some attached property or some other logic to list to the tool tip opening event, and then do an async web service call.

From an MVVM perspective, the VM probably should not care why something wants the data, just that it needs to lazy load it. So you could have a property on the VM (or perhaps even in the Model object) that exposes the data, but lazy-loads the data the first time the property is called. When the async call comes back you just fire the PropertyChanged event on your VM or M which should be interfaced with INotifyPropertyChanged. Then your databinding in the View will pick up the change. The key to getting all this to run when the pop-up of the tooltip occurs is to not bind the data until the tool tip actually does pop-up. It might be worth your time to extend the tooltip to do this, or right your own container to sit inside a tooltip that does this late-databinding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜