datacontext

How do you clear changes in LinqToSql?

ぐ巨炮叔叔 提交于 2019-12-02 02:21:54
问题 I have a combobox in my WPF app that is databound to my list of objects in my View Model. When the user makes changes to the selected object and then selects another item before saving, I need to clear the changes made. I thought I could use dataContext.GetChangeSet().Updates.Clear() but for some reason the collection is read-only. I've also tried to use dataContext.Refresh but this doesn't work either as the object doesn't exist in the database, I created it manually from an SP. Please help.

WPF Show data from multiple DataContexts in ToolTip of ItemsControl

陌路散爱 提交于 2019-12-01 16:32:40
I am trying to display a tooltip for an item generated by an ItemsControl that needs to pull data from conceptually unrelated sources. For example, say I have an Item class as follows: public class Item { public string ItemDescription { get; set; } public string ItemName { get; set; } } I can display the Item within an ItemsControl with a tooltip as follows: <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Items}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding ItemName}"> <TextBlock.ToolTip> <ToolTip> <TextBlock Text="{Binding ItemDescription}" /> </ToolTip> <

WPF's DataContext questions

戏子无情 提交于 2019-12-01 12:56:36
I asked about how does it work with INotifyPropertyChanged interface( How does WPF INotifyPropertyChanged work? ), and it requires me to connect XAML's DataContext to the INotifyPropertyChanged inherit instances as follows. MainViewModel model = new MainViewModel(); this.DataContext = model; And I also found a recommendation to have a comment for DataContext that each XMAL uses( http://joshsmithonwpf.wordpress.com/2009/10/24/xaml-tip-datacontext-comment/ ). When I have multiple XAML files, and when I want to link the DataContext to different ViewModel, I guess I need to make the each XAML.CS

WPF's DataContext questions

梦想的初衷 提交于 2019-12-01 10:26:40
问题 I asked about how does it work with INotifyPropertyChanged interface( How does WPF INotifyPropertyChanged work? ), and it requires me to connect XAML's DataContext to the INotifyPropertyChanged inherit instances as follows. MainViewModel model = new MainViewModel(); this.DataContext = model; And I also found a recommendation to have a comment for DataContext that each XMAL uses( http://joshsmithonwpf.wordpress.com/2009/10/24/xaml-tip-datacontext-comment/ ). When I have multiple XAML files,

How to change the DataContext of a button to the parents parent DataContext?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 06:56:25
问题 I have 2 Classes in WPF: Meeting People In meeting I have 2 ObservableCollections ; AttendingMeeting and NotAttendingMeeting that contain People objects In the xaml the DataContext are set to Meeting , and I have 2 DataGrid s ( AttendingMeeting and NotAttendingMeeting ) I need to add a Button to each of the DataGrid s to add and remove from Meeting , But then I need to change the DataContext on the Button from e.g.: AttendingMeeting to Meeting , so that the Meeting class can handle the adding

Determine the source DataContext for a Linq to Sql query

冷暖自知 提交于 2019-12-01 06:51:05
In my application I have several DataContexts that connects to different databases with different schemas. In a custom user control I display the results of the query and let the user edit them, and when the user edits the data I want to persist the changes to the database. To do that I need a reference to the source DataContext (or at least the source datacontext type) so I can do a DataContext.SubmitChanges(); Is there any way to determine which DataContext a query comes from? The DataQuery class itself is marked as internal, so I can't access its context property without resorting to ugly

My WPF custom control's Data Context is superseding parent's

三世轮回 提交于 2019-12-01 05:55:13
In my main window, I try to bind to a bool. But it's looking in my custom control's data context instead. If I don't assign DataContext in the user control, then the main window's bindings work, but (obviously) this brakes the bindings in the user control. Here's the error: System.Windows.Data Error: 40 : BindingExpression path error: 'MyControlVisible' property not found on 'object' ''MyUserControlModel' (HashCode=1453241)'. BindingExpression:Path=MyControlVisible; DataItem='MyUserControlModel' (HashCode=1453241); target element is 'MyUserControl' (Name='_myUserControl'); target property is

Binding two UserControls to the same DataContext, or ViewModel?

可紊 提交于 2019-12-01 05:46:19
问题 I am working on a UserControl , which is composed of a Chart panel and another area which manipulates some of the chart data i.e. the chart controls (change color of graph, enable or disable stuff on the chart, etc.). I use a ViewModel to manage the chart and its data, but was thinking maybe it would be nice to make a separate usercontrol out of the chart control area to keep my xaml from getting to big and to separate out the components. If I do this though, since the controls would need to

Determine the source DataContext for a Linq to Sql query

ぐ巨炮叔叔 提交于 2019-12-01 05:29:50
问题 In my application I have several DataContexts that connects to different databases with different schemas. In a custom user control I display the results of the query and let the user edit them, and when the user edits the data I want to persist the changes to the database. To do that I need a reference to the source DataContext (or at least the source datacontext type) so I can do a DataContext.SubmitChanges(); Is there any way to determine which DataContext a query comes from? The DataQuery

My WPF custom control's Data Context is superseding parent's

↘锁芯ラ 提交于 2019-12-01 03:04:12
问题 In my main window, I try to bind to a bool. But it's looking in my custom control's data context instead. If I don't assign DataContext in the user control, then the main window's bindings work, but (obviously) this brakes the bindings in the user control. Here's the error: System.Windows.Data Error: 40 : BindingExpression path error: 'MyControlVisible' property not found on 'object' ''MyUserControlModel' (HashCode=1453241)'. BindingExpression:Path=MyControlVisible; DataItem=