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
23
votes
4 answers

How to 'merge' a XAML file and its code-behind with Visual Studio

I have a template defined in a XAML file named 'MyTemplate.xaml'. This template is using a code-behind file named 'MyTemplate.cs'. Mytemplate.xaml:
Morgan M.
  • 846
  • 2
  • 9
  • 27
22
votes
1 answer

UWP: ListView ItemClick not work

I have to do a Master/Detail in UWP 1- If you're in Laptop: The responsible GridView of show the data of this person appear. So when you select a item is binded to ViewModel.
user7332139
22
votes
5 answers

Adding Html from Code Behind in Asp.net

I want to add HTML structure and control like this from code behind into a panel
First Name
22
votes
5 answers

how to add a div to container div in c# code behind

ASP.NET, C# As the title suggests I was wondering if anyone knew how to programatically (c# code behind file) add a div to another a container div (in the aspx page). Thanks in advance
ErnieStings
  • 6,333
  • 19
  • 47
  • 54
22
votes
1 answer

Binding String Property in Code-Behind TextBlock

i am trying to binding a very simple property to a TextBlock, but I have to do all in code-behind (C#). What i am trying to do is: public string SomeText { get; set; } And after I try the Binding on TextBlock: Binding myBinding = new…
Diego Vieira
  • 843
  • 2
  • 8
  • 13
21
votes
3 answers

Set Grid Column/Row width/Height dynamically

I need to create a WPF grid dynamically from code behind. This is going okay and I can do it so that I set the content widths but what I need to do is set them so that when i resize the window the controls are re sized dynamically var col = new…
Welsh King
  • 3,178
  • 11
  • 38
  • 60
20
votes
3 answers

Add existing xaml files to visual studio 2012

I want to add a folder containing xaml and cs files plus other directories to a different project on VS. For some reason when I drag the folder from windows explorer to the project where I will like to place that directory visual studio will not let…
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
19
votes
6 answers

Pragmatic use of code-behind in MVVM pattern

I'm trying to follow the MVVM pattern in a WPF application as good as I can, mainly to be able to create unit tests for my ViewModel logic. In most cases data binding between ViewModel properties and properties of visual elements works fine and is…
Slauma
  • 175,098
  • 59
  • 401
  • 420
19
votes
4 answers

Difference between page_load and onLoad

What is difference between page_load and onLoad functions in ASP.NET codebehind?
Mayur
  • 3,063
  • 10
  • 42
  • 55
18
votes
3 answers

How to set window icon in code behind in wpf?

In xaml it is : /VBDAdvertisement;component/Images/logoVBD.png I want to convert it into code behind. Thanks
JatSing
  • 4,857
  • 16
  • 55
  • 65
18
votes
6 answers

Request.Url.Host and ApplicationPath in one call

Is there any way to get HttpContext.Current.Request.Url.Host and HttpContext.Current.Request.ApplicationPath in one call? Something like "full application url"? EDIT: Clarification - what I need is this the part within…
Marcus L
  • 4,030
  • 6
  • 34
  • 42
18
votes
4 answers

Show context menu from code behind

This might be a simple question, but I've been looking around and can't find the answer. Is there any code to show the context menu on Android from a code, instead of pressing the menu button? E.g. when I touch the screen then it'll call the context…
AnD
  • 3,060
  • 8
  • 35
  • 63
18
votes
3 answers

Disabling all but one child control in a WPF window

I have a bunch of controls on my window. One of them is a refresh button that performs a cumbersome task on a background thread. When the user clicks the refresh button, I put the cursor in a wait (hourglass) status and disable the whole window --…
Rob Sobers
  • 20,737
  • 24
  • 82
  • 111
17
votes
4 answers

how to add a code-behind page to a view or partial view

I notice with the latest version of ASP.NET MVC that a View no longer defaults to having code-behind classes. How do I go about adding a code-behind class now to a View or Partial View??
Andrew Harry
  • 13,773
  • 18
  • 67
  • 102
17
votes
9 answers

Blazor Server - 'Code Behind' pattern: OnInitializedAsync(): no suitable method found to override

I have a Blazor (Server) application which runs perfectly fine, and which adheres to all rules set by Microsoft.CodeAnalysis.FxCopAnalyzers and StyleCop.Analyzers. A heavily cut-down razor page is as follows: @inherits…
DrGriff
  • 4,394
  • 9
  • 43
  • 92