Windows Phone 7 XAML 中的重复转换器错误
在 Windows Phone 7 项目中,我使用的 XAML 如下所示;
<phone:PhoneApplicationPage.Resources>
<ValueConverters:FuelTypeEnumToRadioButtonConverter x:Name="fuelConverter" />
</phone:PhoneApplicationPage.Resources>
在我的页面上,我这样使用它:
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Blyfri95, Converter={StaticResource fuelConverter}}" Content="Blyfri 95" Height="72" HorizontalAlignment="Left" Margin="-1,276,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="FuelType" />
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Blyfri98, Converter={StaticResource fuelConverter}}" Content="Blyfri 98" Height="72" HorizontalAlignment="Left" Margin="154,276,0,0" Name="radioButton2" VerticalAlignment="Top" GroupName="FuelType" />
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Diesel, Converter={StaticResource fuelConverter}}" Content="Diesel" Height="72" HorizontalAlignment="Left" Margin="308,276,0,0" Name="radioButton3" VerticalAlignment="Top" GroupName="FuelType" />
这在实际应用程序中一切正常,但 Visual Studio 中的 XAML 编辑器抱怨“无法在此范围内注册重复的名称‘fuelConverter’”。我必须注释掉初始资源行才能使 XAML 设计器在 Visual Studio 2010 中工作(但是当我运行该应用程序时该应用程序无法工作)。
还有其他人看过这个吗?这只是 XAML 设计器的一个错误吗?
In a Windows Phone 7 project I'm using XAML that looks like this;
<phone:PhoneApplicationPage.Resources>
<ValueConverters:FuelTypeEnumToRadioButtonConverter x:Name="fuelConverter" />
</phone:PhoneApplicationPage.Resources>
and further down on my Page I'm using it like this:
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Blyfri95, Converter={StaticResource fuelConverter}}" Content="Blyfri 95" Height="72" HorizontalAlignment="Left" Margin="-1,276,0,0" Name="radioButton1" VerticalAlignment="Top" GroupName="FuelType" />
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Blyfri98, Converter={StaticResource fuelConverter}}" Content="Blyfri 98" Height="72" HorizontalAlignment="Left" Margin="154,276,0,0" Name="radioButton2" VerticalAlignment="Top" GroupName="FuelType" />
<RadioButton IsChecked="{Binding PreferredFuel, Mode=TwoWay, ConverterParameter=Diesel, Converter={StaticResource fuelConverter}}" Content="Diesel" Height="72" HorizontalAlignment="Left" Margin="308,276,0,0" Name="radioButton3" VerticalAlignment="Top" GroupName="FuelType" />
This all works fine and dandy in the actual application, but the XAML editor in Visual Studio complains that "Cannot register duplicate Name 'fuelConverter' in this scope". I have to comment out the initial Resource-line to get the XAML designer working in Visual Studio 2010 (but then the application doesn't work when I run it).
Anyone else seen this? Is this just a bug with the XAML designer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道不应该是:
使用
x:Key
而不是x:Name
吗?但不确定为什么会出现该错误。
shouldn't that be:
using
x:Key
instead ofx:Name
?Not sure why you get that error, though.
我发现在您的代码中使用 x:Name,
如果有资源或任何命名变量共享此名称,您会在设计时收到此错误,但在运行时工作正常。这就是现实!
我在 silverlight 设计中遇到此错误,因为 myUserControl 和资源名称很常见,因此我将 userControl 的 x:Name 属性更改为 x:Key 然后修复!现在工作正常。
我希望这有帮助。
I see that in your code you use x:Name,
If there is a resource or any named variable share this name you get this error on design time but works fine on runtime. This is reality!
I got this error on silverlight desings because myUserControl and Resource name is common so I changed x:Name attribute to x:Key for userControl then fixed! works fine now.
I hope this helps.