In VS2010 create a new WPF application. In MainWindow.cs declare an unused local variable to generate a compiler warning like so:
namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
int i = 0;
}
}
}
Build the application. The output will appear something like this:
------ Rebuild All started: Project: WpfApplication4, Configuration: Debug x86 ------
D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\MainWindow.xaml.cs(25,8): warning CS0219: The variable 'i' is assigned but its value is never used
Compile complete -- 0 errors, 1 warnings
WpfApplication4 -> D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\bin\Debug\WpfApplication4.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Notice that there is only one mention of unused variable 'i'. Now in MainWindow.xaml add a reference to the local namespace like this:
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
Now rebuild and the output appears like this:
------ Rebuild All started: Project: WpfApplication4, Configuration: Debug x86 ------
D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\MainWindow.xaml.cs(25,14): warning CS0219: The variable 'i' is assigned but its value is never used
Compile complete -- 0 errors, 1 warnings
MainWindow.xaml.cs(25,14): warning CS0219: The variable 'i' is assigned but its value is never used
WpfApplication4 -> D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\bin\Debug\WpfApplication4.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Notice that now there are two mentions of unused variable 'i'.
Why is that and how do I stop it from happening?
EDIT
I've worked out how to make it stop. Just add the name of the local assembly as well as the namespace like so:
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4;assembly=WpfApplication4"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
</Window>
Unfortunately that isn't a solution since in a WPF exe when refering to a namespace in the local assembly you you are not allowed to supply the name of the assembly in the namespace declaration. This will build, but if you try to reference a type in the local assembly it will fail if the assembly name is specified. Using the xmlns:local="clr-namespace:WpfApplication4;assembly=" syntax the double warnings return.
PS Why the down voting? Down voting without comment is lame, how am I supposed to improve the question if you don't tell me what you don't like about it?
It's because it's a bug in VS2010 that MS won't fix.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.