Questions tagged [code-behind]

Code-behind refers to code for your UI (Windows Forms, ASP.NET page, etc.) contained within a separate class file. This allows separation of the UI and the logic behind it.

Code-behind refers to code for your UI (Windows Forms, ASP.NET page, etc.) contained within a separate class file. This allows separation of the UI and the logic behind it.

1955 questions
102
votes
3 answers

Change Canvas.Left property in code behind?

I have a rectangle in my XAML and want to change its Canvas.Left property in code behind:
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
89
votes
7 answers

Accessing a resource via codebehind in WPF

I have a custom collection defined in my window resources as follows (in a Sketchflow app so the window is actually a UserControl): I want to be…
randomsequence
  • 1,338
  • 1
  • 11
  • 14
80
votes
18 answers

The name 'controlname' does not exist in the current context

I have a web application that I'm working on (ASP.NET 2.0 with C#, using Visual Studio 2005). Everything was working fine, and all of a sudden I get the error: Error 1 The name 'Label1' does not exist in the current context and 43 others of the…
zohair
  • 2,369
  • 10
  • 35
  • 41
75
votes
5 answers

How to assign a dynamic resource style in code?

I want to produce in code the equivalent of this in XAML: I can do the text and the width, but how do I assign the dynamic resource to the…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
67
votes
2 answers

How do I access an element of a control template from within code-behind

I'm trying to access a user control which is inside the control template of a content control. Specifically:
Locksleyu
  • 5,192
  • 8
  • 52
  • 77
67
votes
6 answers

ASP.net page without a code behind

I have an ASP.Net page with a C# code behind. However, I've been asked to not use a code behind - so that it will be easier to deploy in SharePoint. Is there a way to include the C# code in the ASP.Net page, without using a separate code behind…
Sophia
  • 5,643
  • 9
  • 38
  • 43
66
votes
7 answers

Adding css class through aspx code behind

I am using aspx. If I have HTML as follows:
I am hoping to dynamically add a css class through the code behind file, ie on Page_Load. Is it possible?
DanDan
  • 10,462
  • 8
  • 53
  • 69
62
votes
5 answers

Why to avoid the codebehind in WPF MVVM pattern?

At the article, WPF Apps With The Model-View-ViewModel Design Pattern, the author who is Josh Smith said: (1) In a well-designed MVVM architecture, the codebehind for most Views should be empty, or, at most, only contain code that manipulates the…
Jin-Wook Chung
  • 4,196
  • 1
  • 26
  • 45
58
votes
7 answers

how to access master page control from content page

I have a master page which contains a label for status messages. I need to set the status text from different .aspx pages. How can this be done from the content page? public partial class Site : System.Web.UI.MasterPage { public string…
LeonidasFett
  • 3,052
  • 4
  • 46
  • 76
52
votes
20 answers

XAML or C# code-behind

I don't like to use XAML. I prefer to code everything in C#, but I think that I am doing things wrong. In which cases it is better to use XAML and when do you use C#? What is your experience?
user101375
  • 6,961
  • 9
  • 42
  • 43
47
votes
1 answer

How to set an event function via a style?

I have several GUI control elements of which some are supposed to generate the same action (code-behind function call) on mouse interaction (MouseEnter, MouseLeave). [edit] I am performing some non style related functionality in my event…
Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
45
votes
1 answer

Simple LINQ and List error: WhereListIterator`1[Task]' to type 'System.Collections.Generic.List`1[Task]'

I'm having trouble understanding my error Method: public List GetAllTasks() { var AllTasks = from t in tasks where t.Status.ToString() == "Completed" || t.Status.ToString() == "Pending" select t; …
Ken Ma
  • 705
  • 2
  • 7
  • 11
44
votes
6 answers

How to programmatically set the Image source

When the Image's Source property is set the following way, the picture is taken from /Images/down.png. How would I do the same thing programmatically? The following would not…
Kornelije Petak
  • 9,412
  • 15
  • 68
  • 96
39
votes
6 answers

Setting up font of TextBox from code behind

How do I set the font of a TextBox from a string in the code behind? // example txtEditor.FontFamily = "Consolas";
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
38
votes
20 answers

Parser Error: Server Error in '/' Application

I got the following error: "An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately." Parser Error Message: `Could not…
Arslan Bilal
  • 625
  • 2
  • 9
  • 17
1
2 3
99 100