datacontext

How do I avoid coupling XAML Views to start up code in a WPF MVVM application?

蹲街弑〆低调 提交于 2019-12-11 07:14:28
问题 I really like the flexibility of declaring my ViewModel on the DataContext of a View through XAML, but I am having a hard time figuring out how I can tie this ViewModel into the rest of the system. Ex. <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ViewModels"> <Window.DataContext> <local:MainViewModel /> </Window.DataContext> The problem here, is that my

ImageTools on Windows Phone 8, changing ImageSource and DataContext

一曲冷凌霜 提交于 2019-12-11 04:42:47
问题 I have problem with DataContext in Windows Phone 8 project. When I run project and MainPage() is done - I see 1st GIF, but when I go Button_Click_1 - 1st GIF is still visible. I have no idea how DataContext work. Is there any way to set DataContext again and display 2nd GIF? namespace PhoneApp1 { public partial class MainPage : PhoneApplicationPage { public Uri ImageSource { get; set; } // Constructor public MainPage() { InitializeComponent(); ImageTools.IO.Decoders.AddDecoder<GifDecoder>();

DataContext values in view code behind

我的未来我决定 提交于 2019-12-11 03:09:20
问题 IN an MVVM pattern is it acceptable or even possible to access ViewModel properties in the views code behind? I have an observable collection which is populated in the ViewModel. I need to use it in the view to bind to an endless ticker with a linked list. i.e. private LinkedList<Border> tickerForex = new LinkedList<Border>(); public ForexBuy() { InitializeComponent(); DataContext = new ForexViewModel(); } private void InitializeForexTicker() { CanvasForexBuyTicker.Children.Clear(); foreach

What is the .cs file under MyDataContext.dbml for?

筅森魡賤 提交于 2019-12-10 18:32:36
问题 What is that individual (currently empty) file under MyDataContext.dbml for? Directory structure: Mydatacontext.dbml MyDataContext.cs MyDataContext.dbml.layout MyDataContext.designer.cs 回答1: It's normally used for you to add a partial MyDataContext class with custom code that won't be overwritten during code generation. If you edited MyDataContext.designer.cs instead, your hand-written code would be erased. 来源: https://stackoverflow.com/questions/936828/what-is-the-cs-file-under-mydatacontext

How to use Linq-to-SQL without having to generate all the classes?

眉间皱痕 提交于 2019-12-10 18:22:44
问题 I have never used Linq-to-Sql before in an application but I used LinqPad to develop a query and just wanted to paste it into into my code. It's not so simple. I guessed that I need a DataContext to handle the connection but I still get errors because the view names aren't recognised. Do I have to use the designer and create all the View/Table- classes? Is there a more simple way? This is the query. Don't need any updates - just this one query.... var q = from user in V020 join userapp in

How to get name of schema from entity framework?

拈花ヽ惹草 提交于 2019-12-10 17:56:09
问题 I have following code using (WdmEntities context = new WdmEntities()) { //get object models from context ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext; var container = objContext.MetadataWorkspace.GetEntityContainer(objContext.DefaultContainerName, DataSpace.CSpace); List<string> schemas = new List<string>(); foreach (var set in container.BaseEntitySets) { foreach (var metaproperty in set.MetadataProperties) { //here if(metaproperty.Name == "Schema") { //but

Bind to DataContext Property from within DataGridColumn

安稳与你 提交于 2019-12-10 17:29:28
问题 Property Foo is in my DataContext ViewModel { Visibility Foo; } But I cannot figure out how to access Foo inside a Column . In this case, I assume it's probably looking for Foo in whatever object is bound to the DataGrid ItemsSource <DataGrid Visibility="{Binding Foo}"> // works <DataGrid.Columns> <DataGridTextColumn Visibility="{Binding Foo}" /> // fails I have tried Binding="{Binding DataContext.Foo}" And a bunch of things with RelativeSource tags as well. Also, is there some way to view

MvvMCross bind to <include> in android layout

风流意气都作罢 提交于 2019-12-10 16:52:45
问题 Is it possible to bind an object X to the include tag, so that the context of binding in the included layout is X ? I want to use a layout multiple times, but not in a list. MainLayout.xml ... <include android:id="@+id/btnDealerMap" android:layout_width="64dp" android:layout_height="64dp" android:visibility="gone" layout="@layout/ServiceBarButtonPhone" local:MvxBind="??? X" /> ... ServiceBarButtonPhone.xml Title and Text are properties of X . <RelativeLayout xmlns:android="http://schemas

How did I wrong my DataContext?

你。 提交于 2019-12-10 16:38:47
问题 I've been working with LINQ To SQL for some time now, and what I usually do in a solution is the following: In a project I create a dbml schema. In another project I create a simple DataAccessLayer (DAL) that knows my first project, and instantiates a DataContext. In the 3rd project (Business logic) I instantiate my DAL. This usually works well. However, this time, I don't know why, but "It" doesn't work. "It" being "Me updating the database". I changed my code around to do some tests, and I

Default datacontext

梦想与她 提交于 2019-12-10 13:48:56
问题 Having the xaml below in MainWindow.xaml: <Window x:Class="TestDependency.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Label Name="someLabel" Grid.Row="0"