code-behind

How to get ListBox ItemsPanel in code behind

*爱你&永不变心* 提交于 2019-12-03 18:01:15
问题 I have a ListBox with an ItemsPanel <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel x:Name="ThumbListStack" Orientation="Horizontal" /> </ItemsPanelTemplate> </Setter.Value> </Setter> I am wanting to move the Stack Panel along the X-axis using a TranslateTransform in code behind. Problem is, I can't find the Stack Panel. ThumbListBox.FindName("ThumbListStack") Returns nothing. I want to use it in: Storyboard.SetTarget(x, ThumbListBox.FindName("ThumbListStack"))

Databinding to CLR property in code-behind

柔情痞子 提交于 2019-12-03 12:52:15
Binding to a Dependency Property is easy in code-behind. You just create a new System.Windows.Data.Binding object, and then call the target dependency object's SetBinding method. But how do you do this when the property which we're binding is a CLR property and you can't provide a DependencyProperty argument to SetBinding ? EDIT: The object implements INotifyPropertyChanged , if that's relevant. rudigrobler Binding targets MUST be dependency properties! That's the only requirement for databinding to work! Read more here: http://msdn.microsoft.com/en-us/library/ms531387(VS.85).aspx http://msdn

Setting Font of TextBox from code behind

本小妞迷上赌 提交于 2019-12-03 10:32:03
问题 This maybe a stupid question but how do I set the font of a TextBox from a string in the code behind? // example txtEditor.FontFamily = "Consolas"; 回答1: txtEditor.FontFamily = new FontFamily("Consolas"); // the Media namespace 回答2: Use the following syntax: lblCounting.Font = new Font("Times New Roman", 50); Where lblCounting is just any label. 回答3: System.Drawing.Font = new Font("Arial", 8, FontStyle.Bold); 回答4: One simple way to do it globally, programmatically: public MainWindow() { this

How to programmatically set the Image source

那年仲夏 提交于 2019-12-03 07:28:09
问题 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? <Image x:Name="myImg" Source="/MyProject;component/Images/down.png" /> The following would not work, since Image.Source property is not of a string type. myImg.Source = "/MyProject;component/Images/down.png"; 回答1: Try this: BitmapImage image = new BitmapImage(new Uri("/MyProject;component/Images/down.png", UriKind.Relative)); 回答2: myImg.Source

Request.Url.Host and ApplicationPath in one call

大兔子大兔子 提交于 2019-12-03 05:52:47
问题 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 []: http://[www.mysite.com/mywebapp]/Pages/Default.aspx I ask simply out of curiosity. EDIT 2: Thanks for all the replies, but none of them were exactly what I was looking for. FYI, I solved the problem this way (but am still interested in knowing if there's a smoother way):

XAML without the .xaml.cs code behind files

孤街醉人 提交于 2019-12-03 05:39:03
问题 I'm using WPF with the Model-View-ViewModel pattern. Thus, my code behind files (.xaml.cs) are all empty, except for the constructor with a call to InitializeComponent. Thus, for every .xaml file I have a matching, useless, .xaml.cs file. I swear I read somewhere that if the code behind file is empty except for the constructor, there is a way to delete the file from the project altogether. After searching the net, it seems that the appropriate way to do this is to use the 'x:Subclass'

Setting Path.Data in code-behind

匿名 (未验证) 提交于 2019-12-03 01:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this XAML code which makes a Path which is inside a Canvas residing in a MainPage.xaml page. <Path x:Name="progressPath" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stroke="Gold" StrokeThickness="5" Canvas.Left="300" Canvas.Top="300" Height="305" Width="305" Data="m 150,0 A 150,0 0 0 0 150,0 A 150,150 0 0 0 150,0"> </Path> I want to have several Path 's like this one (for example, a new Path is made when the user taps a button), so I decided to create them in the code-behind - which doesn't seem to be possible.

Get GridView in Multiple UserControl from codebehind

冷暖自知 提交于 2019-12-02 21:35:15
问题 IpInterfaceUC UserControl: <div id="dvChannel" runat="server" style="height: 205px; width: 550px; overflow: auto; margin-left: 5px;"> <asp:GridView ID="gvChannelUC"> </div> CodeBehind for Init int indexInterface=0; foreach (DataRow row in dtDevicesListByRole.Rows) { ctrIpInterfaceUC = (Test2.SetupGroup.Ipservice.IpInterfaceUC)LoadControl("IpInterfaceUC.ascx"); Control ctr = (Control)ctrIpInterfaceUC; ctr.ID = "device_"+ip+"_"+port+"$"+indexInterface; phDevices.Controls.Add(ctr);//PlaceHolder

How to programmatically set the Image source

£可爱£侵袭症+ 提交于 2019-12-02 20:09:17
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? <Image x:Name="myImg" Source="/MyProject;component/Images/down.png" /> The following would not work, since Image.Source property is not of a string type. myImg.Source = "/MyProject;component/Images/down.png"; Try this: BitmapImage image = new BitmapImage(new Uri("/MyProject;component/Images/down.png", UriKind.Relative)); myImg.Source = new BitmapImage(new Uri(@"component/Images/down.png", UriKind.RelativeOrAbsolute)); Don't forget to set Build

Request.Url.Host and ApplicationPath in one call

陌路散爱 提交于 2019-12-02 18:19:34
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 []: http://[www.mysite.com/mywebapp]/Pages/Default.aspx I ask simply out of curiosity. EDIT 2: Thanks for all the replies, but none of them were exactly what I was looking for. FYI, I solved the problem this way (but am still interested in knowing if there's a smoother way): public string GetWebAppRoot() { if(HttpContext.Current.Request.ApplicationPath == "/") return "http://" +