GetTemplateChild Issue- SLBeta2

Here is another one of those things that might have changed in Beta2. I am not sure what/how should be changed as this was working in Beta1

Sometimes I get the following error

and sometimes Object Reference set to null, I was able to narrow it down to GetTemplateChild in OnApplyTemplate. All the calls to this method return null.

 public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _dropDownButton = GetTemplateChild(“ButtonElement”) as Button;
         _cp = GetTemplateChild(“ContentSite”) as ContentPresenter;
         _border = GetTemplateChild(“border”) as Border;

         _border.Visibility = Visibility.Collapsed          
            _cp.ContentTemplate = ItemTemplate;
            if (_dropDownButton != null)
            {
                _dropDownButton.MouseLeftButtonDown += new MouseButtonEventHandler(_dropDownButton_MouseLeftButtonDown);
                _dropDownButton.IsTabStop = false;
            }
            _rootGrid = GetTemplateChild(“RootElement”) as Grid;            if (_rootGrid != null)           
                _rootGrid.SizeChanged += new SizeChangedEventHandler(RootGrid_SizeChanged);
                     
        }
  

 


Here is the source

Please leave a comment of any solutions/workarounds

Update: Adding DefaultStyleKey=typeof(ComboBox) and DefaultStyleKey=typeof(ComboBoxItem) in the respective Constructors should solve this issue. this is New in Beta2

But I still cant get it to work, I get another exception

Update: If we replace ContentPresenter in ControlTemplates with ContentControl all is good and the issue is resolved (This is workaround for a known bug)

Silverlight DataGrid Issues

I was eager to see how the DataGrid has changed, as the ControlTemplates have changed for the better.

I am not sure if I am doing something wrong but, here are the things I found

Here is the source
1. Here is a screenshot of the DataGrid when we run the application

scroll up and down a few times,Here is what it looks like after

see the difference, ContactTitle column increased its width and Companyname is pushed out, Similar thing happens With Horizontal Scrolling also

2. Sometimes we want to highlight the Rows when a condition is met. I thought LoadingRow event is a good place to check my condition and change the background of the row

so I added the following code

Customer c = e.Row.DataContext as Customer;

if (c.City == “London”)           
   e.Row.Background = new SolidColorBrush(Colors.Yellow);  

it works and we can see the Rows highlighted

Scroll up and down few times and we get

How come just scrolling up and down gives me this, I see LoadingRow event is being raised

3. I thought, may be try  changing the size when the condition is met, so added following code

FrameworkElement ele = grid1.Columns[2].GetCellContent(e.Row);
(ele as TextBlock).FontSize = 20;            

After I added this code, I cannot see all the records

Here is what I have before changing size, the Id’s start with W’s at the end

After changing size, I cannot see these records, I get this, the only way to see the rest of them is to use down keys

Please leave a comment if you have any Idea on what is going on, Thanks

 

Update: looks like a bug and will be fixed by RTM

To get around these issues we have to specify fixed with for the columns, reset the color if the condition is not met.