datacontext

How do I use INotifyPropertyChanged in WinRT?

二次信任 提交于 2019-12-04 22:17:52
I'm a total newbie, just learning the basics of DataContext and the MVVM model. I've now got a grid bound to a view model object which implements INotifyPropertyChanged , however it appears that UpdateSourceTrigger (which all the WPF tutorials tell me to use) is not available for WinRT / Metro Style apps! How do I implement INotifyPropertyChanged then? I'm at the end of my tether here. I've spend nearly the whole day on the most basic of app examples, simply trying to get a grid to update after I click something. The only way I've managed to do this so far is to create an entirely new instance

Linq and DataContext

大城市里の小女人 提交于 2019-12-04 19:06:19
Would it be ok to have only one DataContext per app and share that through an singleton? I ask this because i would like to have the DataContext in every form but i realized that, if i change some enity in one DataContext, i have ro refresh it, if used before. eg form1: db = GetContext() item=(from p in db.Table where p.id=1 select p) on another form db = GetContext() item=(from p in db.Table where p.id=1 select p) item.value="test" back on the original form i have to do db.Refresh(RefreshMode.OverwriteCurrentValues, item) even if i do a new item=(from p in db.Table where p.id=1 select p)

How do you centralize the Entity Framework data context in a web application?

五迷三道 提交于 2019-12-04 17:31:17
In our application we use the repository pattern to retrieve and persist data from our data storage medium. The medium we opted to use is Entity Framework 4. This seems to be a very clean way to do things and has worked great 99% of the time. Now we are encountering an issue. We have two repositories, like this: public class UserRepository : IUserRepository { Entities dataContext = new Entities(); public User GetUser(string username) { return dataContext.Users.SingleOrDefault(x => x.Username == username); } // ... more CRUD-style methods that are not relevant to this question. public void

How to prevent Silverlight RIA Entity getting attached to datacontext before i'm ready

坚强是说给别人听的谎言 提交于 2019-12-04 10:01:01
I have a Silverlight 4 application for a simple 'TODO' list. The problem I'm having is that databinding is hooking up relationships on my TODO object, which causes the RIA data context to add it to the DataContext.TODOs list before I want it there. I want to treat the object as new and detached until I'm explicitly ready to add it to the datacontext. Here's how it works : I've got my TODO entity which is associated with a Status (RIA services entity relationship). I create a new TODO() entity which is passed to a ChildWindow popup. Notice that I don't add this new entity to my datacontext. new

How to set the DataContext for a View created in DataTemplate from ViewModel

霸气de小男生 提交于 2019-12-04 09:02:05
There are questions on this already, but they don't answer my question. For example: <ContentControl.Resources> <DataTemplate DataType="{x:Type Databinding:RedScreenViewModel}" > <Databinding:RedScreen DataContext="{Binding}"/> </DataTemplate> <DataTemplate DataType="{x:Type Databinding:BlueScreenViewModel}"> <Databinding:BlueScreen DataContext="{Binding}" /> </DataTemplate> </ContentControl.Resources> As you can see I am attempting to set the DataContext for the created View hoping that it would use the ViewModel that was used to create it. But when I step through the code behind.. the

WPF MVVM: Setting DataContext of Tab Views

假装没事ソ 提交于 2019-12-04 06:00:26
问题 I have experienced a weird binding behavior that is described here. I did a lot of troubleshooting and I came to the conclusion that the most likely problem lies at how I set the DataContext of each of the tab's view. I have a TabControl whose ItemsSource is bound to a list of ViewModels . MainView: <TabControl ItemsSource="{Binding TabList}"> <TabControl.Resources> <DataTemplate DataType="{x:Type vm:Tab1ViewModel}"> <v:Tab1 /> </DataTemplate> </TabControl.Resources> ... </TabControl>

Ninject and DataContext disposal

。_饼干妹妹 提交于 2019-12-03 22:20:38
I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does Ninject fix this for me? I am investigating this for my colleague Bas. I was looking in the Ninject 2

Calling a custom method in LINQ query

寵の児 提交于 2019-12-03 20:31:59
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 if the number of object fields is large then it's an overkill to duplicate all fields in the second

Multiple/Single *.edmx files per database

江枫思渺然 提交于 2019-12-03 15:09:13
I have a project that interacts with a database through ADO.net Data Services. The database is large ( almost 150 tables with dependencies ). The project started a few years ago and there were DataSets used then; now we're moving towards entity model relationships. The model is growing since we are adding more tables we need to work with. Is this a right way to manage all that?. Meaning should I have a SINGLE database model file to have single data context? What are drawbacks and how do you use the entity framework with large databases (or should it not be used with large ones? The

Saving FrameworkElement with its DataContext to image file does no succeed

牧云@^-^@ 提交于 2019-12-03 13:45:55
I have a simple UserControl called UserControl1 that contains a TextBlock: <UserControl x:Class="WpfApplication2.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <TextBlock Text="{Binding}"/> </Grid> </UserControl> I initialized a new instance of it and gave it a DataContext in code. when the window is closing I