Ok, I have a very simple project to learn about WPF following this video tutorial: https://www.youtube.com/watch?v=Vjldip84CXQ
Everything is OK (and by OK I mean the project can be built AND run)... until I try to change a little part in the XAML from:
<ComboBox SelectedIndex="0">
<ComboBoxItem>Painted</ComboBoxItem>
<ComboBoxItem>Not Painted</ComboBoxItem>
</ComboBox>
to:
<ComboBox x:Name="FinishComboBox" SelectedIndex="0" SelectionChanged="FinishComboBox_SelectionChanged">
<ComboBoxItem>Painted</ComboBoxItem>
<ComboBoxItem>Not Painted</ComboBoxItem>
</ComboBox>
Then it gives me this error, "PresentationFramework.pdb not loaded". And, strangely - at least to me, the solution can be built but CANNOT be run. The error is generated when I try to run (such as by pressing F5 in VS) the solution.
And yes, it is really caused by the XAML change, because if I change the XAML back to:
<!--<ComboBox x:Name="FinishComboBox" SelectedIndex="0" SelectionChanged="FinishComboBox_SelectionChanged">-->
<ComboBox SelectedIndex="0">
<ComboBoxItem>Painted</ComboBoxItem>
<ComboBoxItem>Not Painted</ComboBoxItem>
</ComboBox>
It is working, clean and fine. So my question is obviously why is this so?
I tried some solutions like suggested in:
- https://social.msdn.microsoft.com/Forums/en-US/4c4e2a48-f847-4b94-8adc-58dd000b13ca/visual-studio-presentation-framework-not-loaded?forum=wpf
- Symbol file not loading for debugging custom project in Visual Studio 2012
That includes:
- deleted bin and obj folder from the startup project folder and rebuild the solution
- delete reference to the PresentationFramework then retarget your application framwork and then add PresentationFramework reference again or modified some debug options, clean and rebuild the project.
- Change settings in Debug -> Options -> Debugging -> General, uncheck "Require source files to exactly match the original version"
- Do "Load all symbols" and "Empty Symbol Cache" in Debug -> Options -> Debugging -> Symbols for "All modules, unless excluded"
- some other little things...
But nothing works. Any other solution?
Here is my complete code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfBasics {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void ApplyButton_Click(object sender, RoutedEventArgs e) {
MessageBox.Show($"The description is: {DescriptionText.Text}"); //See how crazy C# is when making things easy for string printing AND it can handle null!!
}
private void ResetButton_Click(object sender, RoutedEventArgs e) {
WeldCheckBox.IsChecked = AssemblyCheckBox.IsChecked = PlasmaCheckBox.IsChecked = LaserCheckBox.IsChecked = PurchaseCheckBox.IsChecked =
LatheCheckBox.IsChecked = DrillCheckBox.IsChecked = FoldCheckBox.IsChecked = RollCheckBox.IsChecked = SawCheckBox.IsChecked = false;
}
private void CheckBox_Checked(object sender, RoutedEventArgs e) {
int length = string.IsNullOrWhiteSpace(LengthText.Text) ? 0 : int.Parse(LengthText.Text);
length += ((CheckBox)sender).Content.ToString().Length;
LengthText.Text = length.ToString();
}
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) {
int length = string.IsNullOrWhiteSpace(LengthText.Text) ? 0 : int.Parse(LengthText.Text);
length -= ((CheckBox)sender).Content.ToString().Length;
LengthText.Text = length.ToString();
}
private void FinishComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
var comboBox = (ComboBox)sender;
var value = (ComboBoxItem)comboBox.SelectedValue;
NoteText.Text = (string)value.Content;
}
}
}
XAML
<Window x:Class="WpfBasics.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfBasics"
mc:Ignorable="d"
Title="WPF Basics v1.0" Height="800" Width="400">
<Border Padding="10">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="ApplyButton" Click="ApplyButton_Click" Margin="0 0 10 0" Grid.Column="0" Content="Apply"/>
<Button x:Name="ResetButton" Click="ResetButton_Click" Margin="0 0 0 0" Grid.Column="1" Content="Reset"/>
<Button Margin="10 0 0 0" Grid.Column="2" Content="Refresh"/>
</Grid>
<!--Margin shorthand 0 10 means left-right = 0, top bottom = 10-->
<!--Pulse Properties-->
<TextBlock Text="Pulse Properties" FontWeight="Bold" Margin="0 10"/>
<!--Description-->
<TextBlock Text="Description"/>
<TextBox x:Name="DescriptionText" Padding="2" />
<!--Status and Revision-->
<Grid Margin="0 5 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="0 0 10 0">
<TextBlock Text="Status"/>
<TextBox Padding="2" IsReadOnly="True" Background="#eeeeee"/>
</StackPanel>
<StackPanel Grid.Column="1">
<TextBlock Text="Revision"/>
<TextBox Padding="2" IsReadOnly="True" Background="#eeeeee"/>
</StackPanel>
</Grid>
<!--Part Number-->
<TextBlock Text="Part Number" Margin="0 5 0 0"/>
<TextBox Padding="2" IsReadOnly="True" Background="#eeeeee"/>
<!--Raw Material-->
<TextBlock Text="Raw Material" FontWeight="Bold" Margin="0 10"/>
<!--Material-->
<TextBlock Text="Material"/>
<ComboBox />
<!--Manufacturing Info-->
<TextBlock Text="Manufacturing Info" FontWeight="Bold" Margin="0 10"/>
<!--Work Centres-->
<TextBlock Text="Work Centres"/>
<!--Checkboxes-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="0 0 10 0">
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="WeldCheckBox" Content="Weld"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="AssemblyCheckBox" Content="Assembly"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="PlasmaCheckBox" Content="Plasma"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="LaserCheckBox" Content="Laser"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="PurchaseCheckBox" Content="Purchase"/>
</StackPanel>
<StackPanel Grid.Column="1">
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="LatheCheckBox" Content="Lathe"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="DrillCheckBox" Content="Drill"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="FoldCheckBox" Content="Fold"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="RollCheckBox" Content="Roll"/>
<CheckBox Unchecked="CheckBox_Unchecked" Checked="CheckBox_Checked" x:Name="SawCheckBox" Content="Saw"/>
</StackPanel>
</Grid>
<!--Length-->
<TextBlock Text="Length" Margin="0 5 0 0"/>
<TextBox x:Name="LengthText" Padding="2"/>
<!--Mass-->
<TextBlock Text="Mass" Margin="0 5 0 0"/>
<TextBox x:Name="MassText" Padding="2" IsReadOnly="True" Background="#eeeeee"/>
<!--Finish-->
<TextBlock Text="Finish" Margin="0 5 0 0"/>
<ComboBox x:Name="FinishComboBox" SelectedIndex="0" SelectionChanged="FinishComboBox_SelectionChanged">
<!--ok if I use the code below-->
<!--<ComboBox SelectedIndex="0">-->
<ComboBoxItem>Painted</ComboBoxItem>
<ComboBoxItem>Not Painted</ComboBoxItem>
</ComboBox>
<!--Purchase Information-->
<TextBlock Text="Purchase Information" Margin="0 5 0 0"/>
<ComboBox SelectedIndex="0">
<ComboBoxItem>Rubber</ComboBoxItem>
<ComboBoxItem>Not Rubber</ComboBoxItem>
</ComboBox>
<!--Supplier Name-->
<TextBlock Text="Supplier Name" Margin="0 5 0 0"/>
<TextBox Padding="2"/>
<!--Supplier Code-->
<TextBlock Text="Supplier Code" Margin="0 5 0 0"/>
<TextBox Padding="2"/>
<!--Additional Information-->
<TextBlock Text="Additional Information" FontWeight="Bold" Margin="0 10"/>
<!--Note-->
<TextBlock Text="Note"/>
<TextBox x:Name="NoteText" Padding="2"/>
</StackPanel>
</Border>
</Window>