datacontext

WPF Usercontrol interaction with parent view / viewmodel

情到浓时终转凉″ 提交于 2019-12-06 14:01:11
问题 Hi I have a mainView window which has its dataContext set to it's own viewModel. On that viewModel is a DateTime property which in turn is bound to a datepicker on my main view using 2 way binding. <toolkit:DatePicker DateSelected="{Binding mainDateTimeProperty, Mode=TwoWay}" /> This is all fine so far. On the change of my datetime property I create a list which is then bound to a datagrid elsewhere on the mainview. This all works fine. My question is to do with a usercontrol I want to add to

Should Linq to SQL repository implement IDisposable

旧时模样 提交于 2019-12-06 08:54:38
问题 I've been googling a ton on repository patterns with Linq over the last few days. There's a lot of info out there but it's often contradictory and I'm still looking for a definitive source. One of the things I'm still not sure about is whether the repository should instantiate it's own DataContext and have a SubmitChanges method, or if the DataContext should be injected and the submission handled externally. I've seen both designs but no real comment on the reasoning. Anyway, the following

C# Linq to SQL connection string (newbie)

只谈情不闲聊 提交于 2019-12-06 06:59:40
i am a new linq to sql learner and this is my very first attempt to create a data viewer program. The idea is simple, i'd like to create a software that is able to view content of a table in a database. That's it. I got an early problem here already and i have seen many tutes and articles online but I still cant fix the bug. Here is my code: static void Main(string[] args) { string cs = "Data Source=localhost;Initial Catalog=somedb;Integrated Security=SSPI;"; var db = new DataClasses1DataContext(cs); db.Connection.Open(); foreach (var b in db.Mapping.GetTables()) Console.WriteLine(b.TableName)

WPF DataContextProxy in resources section

你离开我真会死。 提交于 2019-12-06 05:09:25
问题 I’m having trouble using a DataContextProxy in my WPF application. When I place a DataContextProxy in the Resources section of a Grid it is never loaded. If I move the DataContextProxy out of the resource section everything works correctly. I’ve been investigating this for some time and have tried a number of methods to debug the application. I’ve placed a DebugConverter on the control that I’m trying to use the Proxy with. The Debug converter is never called. I’ve used WPFSnoop to see if

DataContext not set when using View as DataTemplate in ItemsControl

自作多情 提交于 2019-12-06 04:25:02
I have an ObservableCollection of ViewModels that I'd like to bind to an ItemsControl containing the associated child Views. When I add ViewModels to my collection, an appropriate number of child Views are generated in the ItemsControl. However, the DataContext for each of the generated views is null. If I inline my child view, it works correctly. So, what do I need to do to set the DataContext for my child views to my ViewModels? Here's the relavent bits in my parent ViewModel: public ObservableCollection<ChildViewModel> Numbers { get; set; } public ParentViewModel() { Numbers = new

How to programmatically set data binding using C# xaml

人走茶凉 提交于 2019-12-06 04:19:57
How do you programmatically set the DataContext and create a data binding in C# Xaml? Given a Class class Boat : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; internal void OnPropertyChanged(String info) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(info)); } } private int width; public int Width { get { return this.width; } set { this.width = value; OnPropertyChanged("Width"); } } } I am trying to programmatically set the Width of a Xaml Rectangle using data binding. Boat theBoat

Why isn't my transaction escalating to DTC?

大城市里の小女人 提交于 2019-12-05 22:02:22
问题 DTC is disabled on my machine. It is my understanding that this code should fail, because it uses two data contexts in the same transaction. So, why does it work? (Note: I tried this using .NET 3.5 and .NET 4.0.) using (TransactionScope transactionScope = new TransactionScope()) { UpdateEta(); UpdateBin(); transactionScope.Complete(); } Here are the DAL methods that get called: public static void UpdateBin(Bin updatedBin) { using (DevProdDataDataContext dataContext = new

Multi-threading with Linq to SQL

独自空忆成欢 提交于 2019-12-05 17:30:44
I am building an application which requires me to make use of DataContext's inside threads. My application keeps throwing InvalidOperationException 's similar to: There is already an open DataReader associated with this Command which must be closed first ExecuteReader requires an open and available Connection. The connection's current state is connecting These exceptions are intermittant. Here is a snippet of my code: var repo = new Repository(); var entities = repo.GetAllEntities(); foreach (var entity in entities) { ThreadPool.QueueUserWorkItem( delegate { try { ProcessEntity(entity); }

Calling a custom method in LINQ query

江枫思渺然 提交于 2019-12-05 09:01:39
问题 I have a query like this: var q = from u in db.User select new { userId = u.UserId, userName = o.Name, userAvatar = o.AvatarCode }; Then, I have to transform AvatarCode to AvatarPath using custom static method Image.GetPath . It's possible to make this in the following way: var q = (from u in db.User select new { userId = u.UserId, userName = o.Name, userAvatar = o.AvatarCode }) .AsEnumerable() .Select(new { userId = u.UserId, userName = o.Name, userAvatar = Image.GetPath(o.AvatarCode) }; But

Where should I set the DataContext - code behind or xaml?

本秂侑毒 提交于 2019-12-05 02:14:50
(honestly I searched and read all the 'related questions' that seemed relevant - i do hope i didn't "miss" this question from elsewhere but here goes...) There are two different ways (at least) to set the DataContext. One can use XAML or one can use the code behind. What is the 'best practice' and why? I tend to favor setting it in XAML because it allows a designer to define collections on their own but I need 'ammunition' on why it's a best practice or why I'm crazy and the code behind is the bomb... I think it depends on what you are setting the DataContext to, and ultimately personal