Questions tagged [datacontext]
A DataContext is used in WPF, Silverlight and various other .NET technologies. When used with WPF or Silverlight, a DataContext is an object holding the data that the form (or page in case of Silverlight) uses as a display source for its UI elements.
1,477
questions
0
votes
0
answers
27
views
How to add custom datatype mapping to ORM class's properties in C#
We are implementing BigDecimal in C#, reason is existing decimal type has limitations to hold only 29 digits. So for this the first change we have made in SQL table columns. We have defined decimal ...
0
votes
0
answers
34
views
In a MVVM WPF app facing issue to bind a ViewModel function to the Checkbox present in the view [closed]
this is the View:
<DataGridCheckBoxColumn Binding="{Binding Path= 'IsSelected', UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" >
<DataGridCheckBoxColumn....
0
votes
0
answers
26
views
Accessing a code behind property from XAML using the correct DataContext
I have an XCEED Datagrid that changes columns and background colors depending on the contents of the grid. The ProductsOrdered_Shipped column is visible based on the ...
0
votes
1
answer
44
views
Issues with deserialized json and xaml data binding in c#
I'm trying to convert a powershell WPF application I built to C#, but I'm running into an issue with the datacontext/data binding.
In my many searches I ran across the following sample code, but when ...
2
votes
1
answer
56
views
Powershell DataContext variable set to false returns true
I'm using a datacontext in my powershell app (a first for me) and from what I can tell all datacontext properties and values are set with JSON and all values are strings. Example:
$DataObject = ...
0
votes
1
answer
28
views
Modifying property in codebehind doesn't update DataContext binding in ItemsTemplate of ListBox
I made a test project to demonstrate my issue.
In the main window, I define a ListBox and it's ItemTemplate, along with 1 button, Update.
In the DataTemplate I define a CheckBox with IsChecked bound ...
0
votes
0
answers
23
views
.NetCore XUnit access ModelBuilder object of EF DataContext outside DataContext class
I have .Net Core WebApi Application, for which I am writing XUnit tests for Controllers with InMemoryDatabase approach.The actual controllers are injected with DataContext object.
We have an Entity of ...
-3
votes
1
answer
264
views
C# - WPF - Binding Issue - Unable to bind C# properties in XAML
I'm just getting started with WPF in C#, currently using Visual Studio 2019, WPF application in .NET Framework 4.7.2.
I've been struggling with data binding for a few days now, going through numerous ...
0
votes
1
answer
32
views
TextBlock Tooltip converter with multiple data contexts
In my TextBlock.ToolTip I try to use a converter with two inputs. The first one Name just works fine.
Since the TextBlock is inside a DataGrid, I need to change the data context for the second input ...
-1
votes
1
answer
198
views
WPF MVVM - Views does not inherit the Data context from it's parent window
I ask this question after searching though a lot of solution and none of them worked,
My problem can be resumed this way: I have a main window (MainWindow.xaml), I have a view (ParametersView.xaml).
I ...
0
votes
1
answer
46
views
I'm building a web sales platform in ASP.NET Core MVC, what's the best way to structure the DbContext(s)? [closed]
I have:
regular visitors
merchants
and of course our admins and internal team
Do I store all user accounts in the [regular visitors] database, then separate "sensitive" data into a [...
0
votes
0
answers
40
views
How to work with ListViewItems, outside of non-static class in which they were initialised?
I am working on a task list app on WPF that I am new to, and being using MVVM pattern.
What I want is to do is to make the X button on the left of the task to delete it after being pressed. According ...
1
vote
1
answer
39
views
WPF C# Modify ListView Group Header - Data Binding
everyone.
I want to create a ListView that lists items from the Orders class. The list should be grouped by Process.
When I create it as a simple ListView it works fine. I created it following this ...
0
votes
1
answer
60
views
WPF Binding Listbox into ListView (different Source / datacontext)
i have these two classes.
classes:
public class OuterList
{
public string Process { get; set; }
public OuterList(string _process)
{
Process = _process;
}
}
public class ...
0
votes
0
answers
26
views
Why does using Linq with a list and Table entity from DataContext throw a "Local Sequence" exception?
I am using Linq in a .net C# application. I am trying to retrieve results from a Table in my DataContext based on a join with a local list of objects.
I am running into the following error message:
...
0
votes
1
answer
43
views
jQuery selector with null context is safe?
There is a method where I want to find an element by class in a particular html.
someMethod(html) {
$('.some-class', html).click(function(){
...
})
}
And run it like this
someMethod(html)
...
0
votes
2
answers
57
views
Get value of DataContext Result column by variable name
I've been searching and playing around with GetType() for a while, but I keep getting the name of the column (which I already have) and not the value.
I'm trying to build a csv file from the results ...
2
votes
1
answer
102
views
How can I create only one instance of a DataContext for multiple windows?
So I have a WPF program in which I have a ViewModel and several windows. I usually add the DataContext for my ViewModel like this:
<Window.DataContext>
<local:PrintView x:Name="...
0
votes
1
answer
55
views
Why is the Datacontex not updated?
When the selection is changed, the values of the form should be updated but is only updated the name of the task.
<TextBlock HorizontalAlignment="Center" FontSize="20" ...
1
vote
1
answer
33
views
WPF binding child controls DataContext to HierarchicalDataTemplate ItemsSource item
I have a collection of Barcodes that contains a collection of Positions. How do I set the DataContext of a custom control to a Position item in the collection?
<TreeView ItemsSource="{...
0
votes
1
answer
39
views
Change DataContext for ControlTemplate handling
I have a small App where I have a model tree and I want that depending the Item double clicked a different view should appear in the ContentControl.
enter image description here
I have created a ...
1
vote
0
answers
43
views
WPF-Binding is broken when View is closed and reopened
I have a View (MainWindow.Xaml) which has a datacontext set to the MainWindowViewModel and I open it from the MainUIService like the code below.
public class MainUIService
{
void IMainUIService....
0
votes
0
answers
80
views
Error in XAML when setting the DataContext of View
I am getting a rather annoying error in the XAML editor that I can't get rid of. Maybe someone has also had the error and solved it.
The line local:DeviceViewModel/ is underlined with a blue wavy line....
0
votes
1
answer
33
views
Is it possible in WPF to implicitly bind the data context of the usercontrol when using content control with data template?
Right now, the only thing that exists is a control template with a data template.
<ContentControl Grid.Row="1" Content="{Binding CurrentVM,Mode=TwoWay,UpdateSourceTrigger=...
0
votes
0
answers
104
views
create general block-ui component
I have some components I want to use in react-block-ui.
I want to, of course, block the whole site, so I put the blockUi in app.js.
The blockUi data are from context, so that all components have ...
0
votes
1
answer
59
views
WPF Bind color to ellipse and update it automatically
I have this Ellipse with a RadialGradientBrush, where the colors are bind to the colors Light and Dark:
<Grid x:Name="gridEllipse">
<Ellipse x:Name="ellipseMPCenter">
...
0
votes
1
answer
40
views
C# LinqToSql LoadOption with pattern repository
In the project i am maintaining, i have refactoring few logic using the repository pattern over the old ORM (LinqToSql).
My problem now is sometimes i have to share DataContext across repository (this ...
0
votes
0
answers
36
views
How to find the parent data context of a context menu from code behind which have different data context for it's menu item?
Is there any way to get the current instance of an item control by clicking a menuitem where the menuitem itemsource is of different datacontext?
<ItemsControl x:Name="itemscontrol" ...
0
votes
1
answer
20
views
Bind selected item in listview to textbox one way not working as expected
The object from the selected item in the listview is bound over DataContext to several textboxes. It works fine, but it update the listview too if the values in the textbox changes. When a user makes ...
0
votes
1
answer
151
views
Bind to a property in a ResourceDictionary
I have a Templates.xaml file in my project which contains the ResourceDictionary of styles.
I want to bind Direction of a DropShadowEffect to MyNamespace.MyPage.LightDirection. Currently I did this:
//...
0
votes
1
answer
111
views
WPF: programmatically opening context menu loses data context
I would like to reuse the context menu of a ListViewItem by adding a toggle button within the item itself which opens it.
The context menu itself works correctly,
however when I open it through the ...
0
votes
1
answer
126
views
System.ObjectDisposedException when trying to access DataContext
I am trying to get some data from a repository using DbContext. For some reason I keep getting a System.ObjectDisposedException. In my whole code I am not disposing anything and I do not use using ...
0
votes
0
answers
30
views
my database won't save the data because i have an id in the request
I've been trying to solve this problem for hours but I am stuck.
I'm creating a forum using React, Mysql, Express, NodeJs and sequelize
I want to grab the data from the front with a form and send it ...
-1
votes
2
answers
112
views
What is data context in UWP?
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
here this is equivalent to
public string Name{ get; set; } right?
similarly for ...
0
votes
1
answer
36
views
What's the difference in this example between using DataContext in XAML & code behind?
I'm learning binding ways in WPF with DataContext, but I cannot understand why it runs like that.
Here are the codes below.
Ex1: can get correct binding datas (assign DataContext in code behind)
Xaml
&...
0
votes
0
answers
43
views
EF Core - Producing unfiltered queries on all members of dbcontext
I'm writing this here, in the hope that someone has experienced this before and has a thorough answer to this problem.
We have a C# Web API that handles CRUD operations where we are using EF Core as ...
0
votes
1
answer
32
views
How to set a proper context for a ListBox ItemTemplate property in a custom user control
Here is my ListBox Custom control: UCListBox. The MainLabel is the property I have issues with. It is used as a "label" for a ListBox item:
<ListBox ItemsSource="{Binding ItemsSource,...
0
votes
1
answer
236
views
How to assign the ItemsSource of a DataGrid with code behind?
I have a DataGrid in my XAML:
<DataGrid x:Name="dataGridBasket" Width="270" AutoGenerateColumns="True"
ItemsSource="{Binding Path=LoadDataBindingBasket}" ...
0
votes
1
answer
119
views
WPF define DataContext in control inside `ItemsControl`
I have a MainWindow with its xaml and MainViewModel and a FahrtControl with its xaml and FahrtControlViewModel. Inside the MainViewModel, I have an ObservableCollection of FahrtControlViewModel. ...
0
votes
1
answer
46
views
pass interface implementation to a method and invoke AddTransient
How do I pass a class/type to a method which configures IServiceCollection and add's a transient service? I have a generic approach, but how do I pass the implementation of an interface?
...
1
vote
1
answer
72
views
LINQ to SQL not creating Transactions
I've been searching everywhere, to try and get over this issue but I just can't figure this out.
I'm trying to make many changes to the DB with one single transaction using LINQ to SQL.
I've created a ...
0
votes
1
answer
393
views
WPF MVVM binding command to Datacontext inside Datagrid
I'm creating a WPF Molds app that contains 2 windows: MainWindow with DataGrid, and AddEditWindow which allows to Add/Edit Molds.
I have a EditButton which located in a TemplateColumn of DataGrid:
<...
0
votes
1
answer
94
views
How to use a button x:Name or something to indicate button [duplicate]
I have a problem. I have to do app for college, guitar emulator, my idea was to put each fret as a button, and implement the color change function to understand which fret (button) is clamped (pressed)...
0
votes
1
answer
37
views
CartItems returning 0 during debug c#
I need to create an inventory system and currently my cartitems on my controller page is returning 0. This is the code I have on the controller page.
The process is for a receiving warehouse procedure ...
0
votes
2
answers
298
views
DataContext binding in UserControl WPF
Trying to get DataContext in UserControl.
My
structure
I have the model Car
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime....
0
votes
1
answer
80
views
Why does the exe not execute?
half a day that I try to figure out why the exe file generated by VS doesn't start. Hope I can find help! So it is a c# wpf prism App, and it works just fine when started from VS. The exe file however ...
0
votes
1
answer
82
views
Java: Abstract generic data context class
I would like to store all application data in a data context class.
Having application data classes A and B implementing IApplicationData, the non-abstract, non-generic version could look like this:
...
0
votes
1
answer
101
views
WPF TemplateSelector in custom control - usage in code
In my MVVM project, I had to create a custom control RowGrid inheriting from grid.
This control has an ItemsSource and an ItemsTemplateSelector.
(I am not using an ItemsControl, because I need to set ...
3
votes
1
answer
1k
views
"DataContext is not set" message on main window
I'm getting the XLS1106 "DataContext is not set" message on my main window XAML in Visual Studio. As far as I can tell, I haven't used anything related to that and nothing is broken. I would ...
1
vote
2
answers
172
views
WPF UserControl multiple DataContexts?
I currently have an usercontrol with a TreeView and some other things. The TreeView's DataContext is set to the ViewModel and the binding works:
<TreeView Grid.Row="3" Grid.Column="0&...