Sari Rahal
Sari Rahal

Reputation: 1955

WPF Binding a Object to a Control Crash without debug info

I'm trying to bind an object to a control variable and when running the application it errors and gives the error message: "The application is in break mode" Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code). Is there a way to debug this without just putting random break points in the code and start narrowing down?

Also, here is the code that has been causing the issue and not sure why. I'm trying to seporate my current Control into 2 different ones. While trying to bind a object to a control variable, it crashes without ever setting it.

public partial class SummaryFileControl : UserControl {
    public SummaryFileControl() {
        InitializeComponent();
    }

    public SummaryFile SummaryFile {
        get { return (SummaryFile)GetValue(SummaryFileProperty); }
        set { SetValue(SummaryFileProperty, value); }
    }

    // Using a DependencyProperty as the backing store for SummaryFile.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty SummaryFileProperty =
        DependencyProperty.Register("SummaryFile", typeof(SummaryFile), typeof(MainControls), new PropertyMetadata(null));

And then I try to call it using:

<controls:SummaryFileControl SummaryFile="{Binding SumFile}" />

I've also tried this:

<controls:SummaryFileControl SummaryFile="{Binding ElementName=SumFile,Path=SumFile}" />

In the XAML I already reference the object, I am just trying to move it to it's own control and it works just fine like so:

<TextBox Grid.Column="1" Text="{Binding SumFile.ExpectedValue}" IsEnabled="false"  />

Upvotes: 0

Views: 271

Answers (1)

Ayyappan Subramanian
Ayyappan Subramanian

Reputation: 5366

Look at your DependencyProperty declaration, you should mention your control type as SummaryFileControl not as MainControls.

 public static readonly DependencyProperty SummaryFileProperty =
        DependencyProperty.Register("SummaryFile", typeof(SummaryFile), typeof(SummaryFileControl), new PropertyMetadata(null));

Upvotes: 3

Related Questions