![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | getting baml exception regularly... Hello I am getting a baml exception every time a use a control inside my code behind file. For ex consider this xaml code : <Window x:Class="WindowsApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" Title="WindowsApplication1" Width="550" Height="400"> <Window.Resources> <!-- define the XML data source as a resource --> <XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml" XPath="/Favorites"> </XmlDataProvider> <!-- create a data template to display the desired XML node values --> <DataTemplate x:Key="BookmarkDataTemplate"> <StackPanel Margin="5"> <TextBlock FontSize="12" FontWeight="Bold" Foreground="White"> <TextBlock.Text> <Binding XPath="Title"/> </TextBlock.Text> </TextBlock> <TextBlock FontSize="10" Foreground="LightGray"> <TextBlock.Text> <Binding XPath="URL"/> </TextBlock.Text> </TextBlock> </StackPanel> </DataTemplate> </Window.Resources> <!-- write the data to the screen by binding the data template to a list box --> <StackPanel> <TextBlock FontSize="14" FontWeight="Bold" Margin="10">My Favorites</TextBlock> <ListBox x:Name="listbox1" BorderThickness="2" BorderBrush="White" Margin="10" ItemsSource="{Binding Source={StaticResource BookmarkData}, XPath=Bookmark}" ItemTemplate="{StaticResource BookmarkDataTemplate}"/> </StackPanel> </Window> And see the code behind file : using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WindowsApplication1 { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { //int [] values; public Window1() { // values=new int[10]; InitializeComponent(); // int i=listbox1.Items.Count; } } } Every time I uncomment this line // int i=listbox1.Items.Count; I get a baml exception .... Can anyone help me.... |
| | #2 (permalink) |
| Guest | Re: getting baml exception regularly... I think you can write an event handler which will hooks up to Window's Loaded event, and put that line of code into this event handler: for instance: in xaml, you do this: <Window Loaded="WindowLoadedEventHandler"> and in code you do this: private void WindowLoadedEventHandler(Object sender, RoutedEventArgs e) { // int i=listbox1.Items.Count; } Sheva "madhur" <ahuja.madhur@gmail.com> wrote in message news:1141640410.933322.18340@u72g2000cwu.googlegroups.com... > Hello > > I am getting a baml exception every time a use a control inside my code > behind file. For ex consider this xaml code : > > <Window x:Class="WindowsApplication1.Window1" > xmlns="http://schemas.microsoft.com/winfx/avalon/2005" > xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" > Title="WindowsApplication1" Width="550" Height="400"> > <Window.Resources> > <!-- define the XML data source as a resource --> > <XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml" > XPath="/Favorites"> > > </XmlDataProvider> > > <!-- create a data template to display the desired XML node values > --> > <DataTemplate x:Key="BookmarkDataTemplate"> > <StackPanel Margin="5"> > <TextBlock FontSize="12" FontWeight="Bold" Foreground="White"> > <TextBlock.Text> > <Binding XPath="Title"/> > </TextBlock.Text> > </TextBlock> > <TextBlock FontSize="10" Foreground="LightGray"> > <TextBlock.Text> > <Binding XPath="URL"/> > </TextBlock.Text> > </TextBlock> > </StackPanel> > </DataTemplate> > </Window.Resources> > > <!-- write the data to the screen by binding the data template to a > list box --> > <StackPanel> > <TextBlock FontSize="14" FontWeight="Bold" Margin="10">My > Favorites</TextBlock> > <ListBox x:Name="listbox1" > BorderThickness="2" > BorderBrush="White" > Margin="10" > ItemsSource="{Binding Source={StaticResource BookmarkData}, > XPath=Bookmark}" > ItemTemplate="{StaticResource BookmarkDataTemplate}"/> > </StackPanel> > > </Window> > > And see the code behind file : > > using System; > using System.Windows; > using System.Windows.Controls; > using System.Windows.Data; > using System.Windows.Documents; > using System.Windows.Media; > using System.Windows.Media.Imaging; > using System.Windows.Shapes; > > > namespace WindowsApplication1 > { > /// <summary> > /// Interaction logic for Window1.xaml > /// </summary> > > public partial class Window1 : Window > { > //int [] values; > public Window1() > { > // values=new int[10]; > InitializeComponent(); > > // int i=listbox1.Items.Count; > > } > > > } > } > > Every time I uncomment this line // int i=listbox1.Items.Count; > I get a baml exception .... > > Can anyone help me.... > |
| | #3 (permalink) |
| Guest | Re: getting baml exception regularly... And even then you have to be carefull. I found that many times the controls haven't been rendered by then. So they do exist but ActualHeight and ActualWidth might be 0 or NaN. To force the controls to be drawn and sized at least once you can use UpdateLayout() (Don't call that too often!) -- Erno ---- WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx "Sheva" <footballism@gmail.com> wrote in message news:utdsGnSQGHA.3272@tk2msftngp13.phx.gbl... >I think you can write an event handler which will hooks up to Window's >Loaded event, and put that line of code into this event handler: > for instance: > in xaml, you do this: > <Window Loaded="WindowLoadedEventHandler"> > and in code you do this: > private void WindowLoadedEventHandler(Object sender, RoutedEventArgs e) > { > // int i=listbox1.Items.Count; > } > > Sheva > "madhur" <ahuja.madhur@gmail.com> wrote in message > news:1141640410.933322.18340@u72g2000cwu.googlegroups.com... >> Hello >> >> I am getting a baml exception every time a use a control inside my code >> behind file. For ex consider this xaml code : >> >> <Window x:Class="WindowsApplication1.Window1" >> xmlns="http://schemas.microsoft.com/winfx/avalon/2005" >> xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" >> Title="WindowsApplication1" Width="550" Height="400"> >> <Window.Resources> >> <!-- define the XML data source as a resource --> >> <XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml" >> XPath="/Favorites"> >> >> </XmlDataProvider> >> >> <!-- create a data template to display the desired XML node values >> --> >> <DataTemplate x:Key="BookmarkDataTemplate"> >> <StackPanel Margin="5"> >> <TextBlock FontSize="12" FontWeight="Bold" Foreground="White"> >> <TextBlock.Text> >> <Binding XPath="Title"/> >> </TextBlock.Text> >> </TextBlock> >> <TextBlock FontSize="10" Foreground="LightGray"> >> <TextBlock.Text> >> <Binding XPath="URL"/> >> </TextBlock.Text> >> </TextBlock> >> </StackPanel> >> </DataTemplate> >> </Window.Resources> >> >> <!-- write the data to the screen by binding the data template to a >> list box --> >> <StackPanel> >> <TextBlock FontSize="14" FontWeight="Bold" Margin="10">My >> Favorites</TextBlock> >> <ListBox x:Name="listbox1" >> BorderThickness="2" >> BorderBrush="White" >> Margin="10" >> ItemsSource="{Binding Source={StaticResource BookmarkData}, >> XPath=Bookmark}" >> ItemTemplate="{StaticResource BookmarkDataTemplate}"/> >> </StackPanel> >> >> </Window> >> >> And see the code behind file : >> >> using System; >> using System.Windows; >> using System.Windows.Controls; >> using System.Windows.Data; >> using System.Windows.Documents; >> using System.Windows.Media; >> using System.Windows.Media.Imaging; >> using System.Windows.Shapes; >> >> >> namespace WindowsApplication1 >> { >> /// <summary> >> /// Interaction logic for Window1.xaml >> /// </summary> >> >> public partial class Window1 : Window >> { >> //int [] values; >> public Window1() >> { >> // values=new int[10]; >> InitializeComponent(); >> >> // int i=listbox1.Items.Count; >> >> } >> >> >> } >> } >> >> Every time I uncomment this line // int i=listbox1.Items.Count; >> I get a baml exception .... >> >> Can anyone help me.... >> > > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exception stack is corrupt when catching and storing the exception | Morten Herman Langkjaer | .NET General | 1 | 03-05-2008 02:11 AM |
| Vista Install Error: Exception Unknown Software Exception | burntham77 | Vista installation & setup | 2 | 01-07-2008 01:39 PM |
| Vista regularly shuts down | Charlie | Vista General | 1 | 10-02-2007 12:59 PM |
| Losing netowork regularly | mister.jones | Vista networking & sharing | 34 | 06-18-2007 05:05 AM |
| baml parse error - November CTP | wolfi | Avalon | 4 | 01-10-2006 03:52 PM |