code-behind

How to set an event function via a style?

旧时模样 提交于 2019-11-28 22:33:55
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 handlers. Right now I'm using event attributes in each control: <Button Name="Button" Content="Button 1" MouseEnter="GeneralMouseEnter" MouseLeave="GeneralMouseLeave" PreviewMouseDown="Button1_PreviewMouseDown" PreviewMouseUp="Button1_PreviewMouseUp" /> <Button Name="NotInteractingButton" Content="Button 2" /><!-- this button has no MouseOver-effects -->

ASP.net page without a code behind

孤者浪人 提交于 2019-11-28 18:31:26
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 file? By default Sharepoint does not allow server-side code to be executed in ASPX files. See this for how to resolve that. However, I would raise that having a code-behind is not necessarily difficult to deploy in Sharepoint (we do it extensively) - just compile your code-behind classes into an assembly and deploy it using a solution . If still no, you

XAML or C# code-behind

强颜欢笑 提交于 2019-11-28 16:58:37
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? Creating an entire window in C# can be a mess of code. The best thing about WPF is that XAML allows you to separate your design from your logic, making for much easier-to-read code. I'll use C# when I need to create dynamic controls, but I tend to keep my general design, static storyboards, styles, datatemplates, etc. in XAML. JP Alioto Check out this video on MVVM in WPF. If you want wrap your head

How to assign a dynamic resource style in code?

我与影子孤独终老i 提交于 2019-11-28 16:26:18
问题 I want to produce in code the equivalent of this in XAML: <TextBlock Text="Title:" Width="{Binding FormLabelColumnWidth}" Style="{DynamicResource FormLabelStyle}"/> I can do the text and the width, but how do I assign the dynamic resource to the style: TextBlock tb = new TextBlock(); tb.Text = "Title:"; tb.Width = FormLabelColumnWidth; tb.Style = ??? 回答1: You can try: tb.Style = (Style)FindResource("FormLabelStyle"); Enjoy! 回答2: You should use FrameworkElement.SetResourceReference if you want

Animate Margin / Thickness

帅比萌擦擦* 提交于 2019-11-28 12:12:39
I just thought I already know how WPF and XAML Syntax works.... wrooong. I got the message: 'WithEvents' variables can only be typed as classes, interfaces or type parameters with class constraints. Please, do you know why this syntax is wrong? I need to use the single value as double. It works later with an storyboard in codebehind. Regards I just want to animate the Red rectangle with a storyboard in location and size. Perhaps XAML is the right solution anyway? To animate thickness, use a Storyboard like this (from msdn example): <BeginStoryboard> <Storyboard> <!-- BorderThickness animates

How to Set Image Resource URI from Code-Behind

允我心安 提交于 2019-11-28 12:04:08
I am trying to embed a PNG graphic into a DLL and load it into an Image control as a BitmapImage . However, WPF keeps throwing an exception saying that the resource cannot be found. First, some minimal sample code and the steps to reproduce the problem: Create a WPF project named ImageResTest with an empty main window (you can set the default namespace to ImageResTest ). The code-behind file of the main window should look like this: using System; using System.Windows; using System.Windows.Controls; namespace ImageResTest { public partial class Window1 : Window { public Window1() {

HyperLink with NavigateUrl with Eval(). Where is the mistake?

痴心易碎 提交于 2019-11-28 11:54:30
First I was changing HyperLink.NavigateUrl in code-behind on Page_Load() . But after I decided to do it in design using Eval() method. <asp:HyperLink runat="server" NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" /> or <asp:HyperLink ID="urlRefuse" runat="server" NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" /> where id and type - are variables from Request . But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance. Hamdy Mohamed

Set Text property of asp:label in Javascript PROPER way

自古美人都是妖i 提交于 2019-11-28 10:46:41
I have a series of textboxes on a form. When the user inserts numbers into these textboxes, calculations are made and <asp:Label> controls are updated via JavaScript to reflect these calculations: document.getElementById('<%=TotalLoans.ClientID %>').innerHTML = TotalLoans; This correctly updates the UI. However, when I try to access the value in the codebehind, the Text property is empty. This makes sense I guess, since I was updating the innerHTML property via the JavaScript. //TotalLoans.Text will always be equal to "" in this scenario double bTotalLoans = string.IsNullOrEmpty(TotalLoans

OnDataBinding vs Inline: pros, cons and overhead

这一生的挚爱 提交于 2019-11-28 09:16:24
I thought I would ask this question to see why many examples and people prefer to use inline databinding in the aspx code vs implementing an OnDataBinding event when using WebForms. For any databound control (eg. Repeater, GridView, etc) I always implement the OnDataBinding method for field level controls if I need to do anything that isn't built in out of the box (eg. I need to do an Eval). Most examples I see have the code right in the aspx page using the inline <%# syntax. Example of inline ASP.NET code: <asp:Literal ID="litExample" runat="server" Text='<%# Eval("ExampleField").ToString() %

Difference between page_load and onLoad

限于喜欢 提交于 2019-11-28 08:23:42
What is difference between page_load and onLoad functions in ASP.NET codebehind? Load is the event and OnLoad is a method that raises that event when called it's just base class implementation that does it of course, and therefore needs to be called from deriving classes so that events work) You should probably read the Page Lifecycle Overview for more info. This little bit should help clear up the difference: Note that when an event handler is created using the Page_event syntax, the base implementation is implicitly called and therefore you do not need to call it in your method. For example,