Click here to Skip to main content
15,888,461 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Changing Button Programatically [SLVED, but still accepting input/comments] Pin
Michael J. Eber19-Apr-10 11:49
Michael J. Eber19-Apr-10 11:49 
QuestionChart ToolKit error in WPF Pin
Nanda_MR6-Apr-10 1:36
Nanda_MR6-Apr-10 1:36 
Questionwpf menu errors in XP Pin
hb521342145-Apr-10 13:24
hb521342145-Apr-10 13:24 
AnswerRe: wpf menu errors in XP Pin
hb521342145-Apr-10 13:54
hb521342145-Apr-10 13:54 
QuestionContext Menu Pin
ScottRadel5-Apr-10 12:09
ScottRadel5-Apr-10 12:09 
AnswerRe: Context Menu Pin
hb521342145-Apr-10 13:56
hb521342145-Apr-10 13:56 
GeneralRe: Context Menu Pin
ScottRadel6-Apr-10 8:21
ScottRadel6-Apr-10 8:21 
QuestionSetting a Style Programatically [modified] Pin
#realJSOP5-Apr-10 9:36
mve#realJSOP5-Apr-10 9:36 
I have a StackPanel specified in the XAML, and I'm trying to add children to it programatically. My code looks something like this:

First the Xaml... (I would have formatted this correctly, but CP is blowing chunks on the formatting stuff, so you're getting this as plain text)

<UserControl.Resources>
<Style x:Key="BorderStyle" TargetType="Border">
...
</Style>

<Style x:Key="LabelStyle" TargetType="dataInput:Label">
...
</Style>
</UserControl>

<Grid>
<StackPanel Name="stackPanel" Orientation="Horizontal" Height="60" >
<Border Width="300"/>
</StackPanel>
</Grid>

And in my CS code (being called from the <code>UserControl</code>'s constructor, after <code>InitializeComponent()</code>...

<pre>Border border = new Border()
border.Style = this.Resources["BorderStyle"] as Style;
Label label = new Label();
label.Style = this.Resources["LabelStyle"] as Style;
border.Child = label;
stackPanel.Children.Add(border);
</pre>

When I run the code, I get a "Catastrophic failure" exception, and as you might guuess, the app dies a horrible death. What am I doing wrong?


-- Modified Monday, April 5, 2010 3:57 PM
AnswerRe: Setting a Style Programatically Pin
Pete O'Hanlon5-Apr-10 10:46
mvePete O'Hanlon5-Apr-10 10:46 
GeneralRe: Setting a Style Programatically Pin
#realJSOP5-Apr-10 12:14
mve#realJSOP5-Apr-10 12:14 
GeneralRe: Setting a Style Programatically Pin
Pete O'Hanlon6-Apr-10 9:03
mvePete O'Hanlon6-Apr-10 9:03 
GeneralRe: Setting a Style Programatically Pin
#realJSOP6-Apr-10 9:17
mve#realJSOP6-Apr-10 9:17 
QuestionText Rotation - Is It Just Me? Pin
#realJSOP5-Apr-10 0:04
mve#realJSOP5-Apr-10 0:04 
AnswerRe: Text Rotation - Is It Just Me? Pin
Pete O'Hanlon5-Apr-10 10:20
mvePete O'Hanlon5-Apr-10 10:20 
QuestionSilverlight Automatic Image Transition Pin
saurabh94-Apr-10 23:03
saurabh94-Apr-10 23:03 
AnswerRe: Silverlight Automatic Image Transition Pin
Michael J. Eber19-Apr-10 11:54
Michael J. Eber19-Apr-10 11:54 
QuestionRotaing Label control Pin
#realJSOP4-Apr-10 5:58
mve#realJSOP4-Apr-10 5:58 
AnswerRe: Rotaing Label control Pin
Abhinav S4-Apr-10 6:50
Abhinav S4-Apr-10 6:50 
GeneralRe: Rotaing Label control Pin
#realJSOP4-Apr-10 7:02
mve#realJSOP4-Apr-10 7:02 
GeneralRe: Rotaing Label control Pin
Abhinav S4-Apr-10 7:11
Abhinav S4-Apr-10 7:11 
GeneralRe: Rotaing Label control Pin
#realJSOP4-Apr-10 7:51
mve#realJSOP4-Apr-10 7:51 
QuestionImage.ImageSource to string ? Pin
Mohammad Dayyan3-Apr-10 16:58
Mohammad Dayyan3-Apr-10 16:58 
AnswerRe: Image.ImageSource to string ? Pin
Abhinav S3-Apr-10 18:09
Abhinav S3-Apr-10 18:09 
QuestionWPF DataGrid row backgound Pin
koleraba3-Apr-10 7:47
koleraba3-Apr-10 7:47 
AnswerRe: WPF DataGrid row backgound Pin
Abhinav S3-Apr-10 7:59
Abhinav S3-Apr-10 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.