![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Resources doesn't work at all? Hi, In the book WPF (O'REILLY) they have a simple example looking like this. <Window x:Class=".... > <Window.Resources> <SolidColorBrush x:Key="Foo" Collor="Green" /> ... </Window.Resources> <Grid Name="myGrid"> <!-- I have tried x:Name="myGrid" --> </Grid> </Window> Code-Behind: Brush b = (Brush)myGrid.FindResource("Foo"); <!-- This will not work, it will throw an exception. --> I have tried following things too. Brush b = (Brush)this.Resources["Foo"]; <!-- Will not throw exception but return value will be Null --> Brush b = (Brush)this.FindResource("Foo"); <!-- Will throw exception --> /Please help |
My System Specs![]() |
| | #2 (permalink) |
| Guest | RE: Resources doesn't work at all? Where in the code-behind did you try? The line Brush b = (Brush)this.FindResource("Foo"); should work, but maybe you have tried this in the constructor. Try with the code in the Window's Loaded event. -- Valentin Iliescu [MVP - Client Application Development] "HokutoNoKen" wrote: > Hi, > > In the book WPF (O'REILLY) they have a simple example looking like this. > > <Window x:Class=".... > > > > > <Window.Resources> > <SolidColorBrush x:Key="Foo" Collor="Green" /> > ... > </Window.Resources> > > <Grid Name="myGrid"> <!-- I have tried x:Name="myGrid" --> > </Grid> > </Window> > > Code-Behind: > > Brush b = (Brush)myGrid.FindResource("Foo"); <!-- This will not work, it > will throw an exception. --> > > I have tried following things too. > > Brush b = (Brush)this.Resources["Foo"]; <!-- Will not throw exception but > return value will be Null --> > Brush b = (Brush)this.FindResource("Foo"); <!-- Will throw exception --> > > /Please help > > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Resources doesn't work at all? Add loaded on the window , see below and the eventhandler Windowloaded in the code behind Window1.xaml : <Window x:Class="WindowsApplication8.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowsApplication10" Height="300" Width="300" Loaded="WindowLoaded" > <Window.Resources> <Ellipse x:Key="shape" Fill="Blue" Width="100" Height="80" /> </Window.Resources> <DockPanel x:Name="myDockPanel"></DockPanel> </Window> Window1.xaml.cs: private void WindowLoaded(object sender, RoutedEventArgs e) { // Add button Button myButton = new Button(); myButton.Content = "Click me!"; this.myDockPanel.Children.Add(myButton); Ellipse myEllipse = (Ellipse)this.FindResource("shape"); this.myDockPanel.Children.Add(myEllipse); } Regards, Tommy "HokutoNoKen" <tommy.herceg@programgruppen.se> wrote in message news:%23Tys9NsaGHA.3736@TK2MSFTNGP04.phx.gbl... > Hi, > > In the book WPF (O'REILLY) they have a simple example looking like this. > > <Window x:Class=".... > >> > > <Window.Resources> > <SolidColorBrush x:Key="Foo" Collor="Green" /> > ... > </Window.Resources> > > <Grid Name="myGrid"> <!-- I have tried x:Name="myGrid" --> > </Grid> > </Window> > > Code-Behind: > > Brush b = (Brush)myGrid.FindResource("Foo"); <!-- This will not work, it > will throw an exception. --> > > I have tried following things too. > > Brush b = (Brush)this.Resources["Foo"]; <!-- Will not throw exception but > return value will be Null --> > Brush b = (Brush)this.FindResource("Foo"); <!-- Will throw exception --> > > /Please help > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VPN / Local resources | skaas | Vista networking & sharing | 2 | 06-27-2008 04:03 AM |
| Not enough resources | Eric the Grey | Vista hardware & devices | 4 | 03-13-2007 10:13 PM |
| resources | Banjaxster | Vista hardware & devices | 10 | 11-13-2006 09:35 PM |
| Vista using 100% resources | Exiddor | Vista General | 0 | 06-16-2006 01:02 AM |
| Using Resources | Erno | Avalon | 3 | 01-31-2006 06:59 AM |