This is a migrated thread and some comments may be shown as answers.

Windows XP Data Binding crashes application

3 Answers 161 Views
Window
This is a migrated thread and some comments may be shown as answers.
Fabian
Top achievements
Rank 1
Fabian asked on 06 Nov 2017, 03:48 PM

I just got these Problem on Windows XP.

If any binded value get changed, the PropertyChanged event will throw an exception.

 

XAML-Code:

01.<telerik:RadWindow x:Class="TelerikWpfApp.TelerikScenario"
04.        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
05.        Header="TelerikScenario" Height="300" Width="300">
06.    <Grid>
07.        <Grid.ColumnDefinitions>
08.            <ColumnDefinition />
09.            <ColumnDefinition />
10.        </Grid.ColumnDefinitions>
11. 
12.        <Label Content="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Grid.Column="0" />
13. 
14.        <Button Content="CHANGE VALUE" Click="Button_Click" Grid.Column="1" Height="150" Margin="5" />
15.    </Grid>
16.</telerik:RadWindow>

 

Code Behind:

using System;
using System.ComponentModel;
using System.Windows;
 
namespace TelerikWpfApp
{
    /// <summary>
    /// Interaction logic for TelerikScenario.xaml
    /// </summary>
    public partial class TelerikScenario : INotifyPropertyChanged
    {
        #region Private Fields
        private string text = "test";
        #endregion Private Fields
 
        #region Public Events
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion Public Events
 
        #region Protected Methods
        protected void SetProperty<T>(ref T storage, T value, string property = null)
        {
            if (Object.Equals(storage, value)) return;
            storage = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
        }
        #endregion Protected Methods
 
        #region Public Properties
        public string Text
        {
            get { return text; }
            set { SetProperty(ref text, value); }
        }
        #endregion Public Properties
 
        #region Public Constructors
 
        public TelerikScenario()
        {
            InitializeComponent();
            DataContext = this;
        }
 
        #endregion Public Constructors
 
        #region Private Methods
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Text = "123";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion Private Methods
    }
}

 

Exception:

Cannot change AllowsTransparency after a Window has been shown or
WindowInteropHelper.EnsureHandle has been called.

 

  at System.Windows.Window.CoerceAllowsTransparency(DependencyObject d, Object value)
  at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp,
  PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex,
  EffectiveValueEntry& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue,
  Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback,
  Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, Boolean
  skipBaseValueChecks)
  at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,
  DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry,
  EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean
  coerceWithCurrentValue, OperationType operationType)
  at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
  at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean
  isASubPropertyChange)
  at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean
  isASubPropertyChange)
  at System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean
  isASubPropertyChange)
  at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean
  dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
  at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k,
  ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
  at MS.Internal.Data.ClrBindingWorker.OnSourcePropertyChanged(Object o, String
  propName)
  at
  MS.Internal.Data.PropertyPathWorker.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type
  managerType, Object sender, EventArgs e)
  at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs
  args, ListenerList list)
  at System.ComponentModel.PropertyChangedEventManager.OnPropertyChanged(Object
  sender, PropertyChangedEventArgs args)
  at TelerikWpfApp.TelerikScenario.SetProperty[T](T& storage, T value, String
  property) in C:\Users\BL\Documents\Visual Studio
  2017\Projects\TelerikWpfApp\TelerikWpfApp\TelerikScenario.xaml.cs:line 39
  at TelerikWpfApp.TelerikScenario.set_Text(String value) in
  C:\Users\BL\Documents\Visual Studio
  2017\Projects\TelerikWpfApp\TelerikWpfApp\TelerikScenario.xaml.cs:line 47
  at TelerikWpfApp.TelerikScenario.Button_Click(Object sender, RoutedEventArgs e)
  in C:\Users\BL\Documents\Visual Studio
  2017\Projects\TelerikWpfApp\TelerikWpfApp\TelerikScenario.xaml.cs:line 66

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 08 Nov 2017, 02:15 PM
Hi Fabian,

I tried to reproduce your scenario with the sample code you provided, but I am afraid I wasn't able to do so. I am not sure how you connect the your TelerikScenario object to the RadWindow.  According to the error message it seems like you are changing the AllowsTransparancy property of the window after it has been shown. Can you take a look at the article and see if the exception you are receiving is the same? If you need any further assistance, may I ask you to provide a sample project to further illustrate your scenario, so that I may better assist you.

One more thing that I noticed is that you can inherit our ViewModelBase class, which already implements the INotifyPropertyChanged interface for easier use.

I am looking forward to hearing from you.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Fabian
Top achievements
Rank 1
answered on 13 Nov 2017, 07:14 AM

This is the code from MainWindow.cs:

 

public partial class MainWindow : RadRibbonWindow
    {
        #region Public Constructors
        public MainWindow()
        {
            InitializeComponent();
        }
        #endregion Public Constructors
 
        #region Private Methods
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TelerikScenario telerikScenario = new TelerikScenario();
            telerikScenario.ShowDialog();
        }
        #endregion Private Methods
    }

 

The shown exceptions are not the same.

0
Vladimir Stoyanov
Telerik team
answered on 15 Nov 2017, 03:36 PM
Hi Fabian,

Unfortunately, I am still unable to reproduce the issue you've described at my end. May I kindly ask you to isolate the issue in a small sample project and send it over in a new support ticket so that we can observe the issue on our side and suggest possible solutions for it?

Thank you in advance for your cooperation.

Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Window
Asked by
Fabian
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Fabian
Top achievements
Rank 1
Share this question
or