tags:

views:

22

answers:

1

Dear team, this is my problem:

Inside a control I have a generic number (I know it only at runtime) of sub controls. Each sub-control is a LanguageTextView which contains a rich text editor from Liquid. A button is used to control how these rich texts have to be shown inside the parent control. There are 2 options: a single LanguageTextView or all the LanguageTextView items equally spaced inside the parent control.

To solve this problem I used a Grid in the container. With code behind I populate the grid with rich texts on the "load" event:

foreach (OM_Language lang in LanguageDataManager.INSTANCE.ActiveLanguages) {

    LanguageTextView tb = new LanguageTextView();
    tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
    tb.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch;
    tb.HorizontalAlignment = HorizontalAlignment.Stretch;
    tb.HorizontalContentAlignment = HorizontalAlignment.Stretch;
    tb.init(lang);

    tb.onTextChangedEvent += new    LanguageTextView.onTextChangedEventType(tb_onTextChangedEvent);

    if ((_module.Texts != null) && (_module.Texts.ContainsKey(lang.OMID.Value))) {
      tb.Text = _module.Texts[lang.OMID.Value];
    }

    _textBoxList.Add(lang.OMID.Value, tb);
  }

_textBoxList is a dictionary which is passed to a grid controller with the grid object to control. Grid controller, called MultiLanguageGridController, handle how LanguageTextView have to be shown inside the grid (a single object or all the objects together). As first step, when created, grid controller place the LanguageTextView one per column with following code:

  int count = 0;
  foreach (int key in _uiElements.Keys) {
    FrameworkElement fe = _uiElements[key];

    ColumnDefinition cd = new ColumnDefinition();
    cd.Width = new GridLength(1, GridUnitType.Star);
    _cds.Add(key, cd);

    _grid.ColumnDefinitions.Add(cd);
    _grid.Children.Add(fe);

    Grid.SetColumn(fe, count);
    Grid.SetRow(fe, 0);

    count++;
  }

To control layout there are two methods: showAllObjects and showSingleObjet(objectid).

showAllObject is like this:

foreach (int key in _uiElements.Keys) {
  _cds[key].Width = new GridLength(1, GridUnitType.Star);
}

showSingleObject is as follow:

foreach(int key in _uiElements.Keys){
    if(key == objectId){
      _cds[key].Width = new GridLength(1, GridUnitType.Star);
    }else{
      _cds[key].Width = new GridLength(0);
    }
  }

When control button is pressed, the button event is handled this way:

  ModuleListItemData mld = this.DataContext as ModuleListItemData;
  if (mld == null) {
    return;
  }
  mld.IsShowAllLanguages = !mld.IsShowAllLanguages;

IsShowAllLanguages is a property which fires a property changed event. Property changed event is intercepted and handled this way:

  if ("IsShowAllLanguages".Equals(e.PropertyName)) {
    if (tmd.IsShowSingleLanguage) {
      _gridCtrl.showSingleObject(tmd.SelectedLanguage.OMID.Value);
    } else {
      _gridCtrl.showAllObjects();
    }

    return;
  }

Where _gridCtrl is a reference to MultiLanguageGridController.

After second round-trip on button event handling, application crashes. Debugging the application, I setup a break point at the last line of button clich event handler as follows:

private void _btnShowAllLang_Click(object sender, RoutedEventArgs e) {
  ModuleListItemData mld = this.DataContext as ModuleListItemData;
  if (mld == null) {
    return;
  }
====>  mld.IsShowAllLanguages = !mld.IsShowAllLanguages; <=== Break point here
}

Each time the control button is pressed, break point is reached, but right after exiting from method pressing F10 (visual studio 2010), application stops and after I while I get an exception:

An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.dll. Trying to read protected memory.

I'm not able to proceed with debugging outside the event handler method! Any ideas??

Thanks in advance for any support.

A: 

Strange but true, the solution was to change XAML inclusion from:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:myConverters="clr-namespace:ArgoWeb.Utility.Data" 
mc:Ignorable="d" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
d:DesignWidth="608" d:DesignHeight="112"

to:

xmlns:my="clr-namespace:ArgoWeb.UI.UserControls.ModuleView"  
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:local="clr-namespace:ArgoWeb.Utility.Data"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
mc:Ignorable="d" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
d:DesignWidth="482" d:DesignHeight="144" Height="100"

This solved the problem.

Paolo Mosna