Windows Phone 7 XAML 中的重复转换器错误

发布于 2024-10-09 23:10:00 字数 1373 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-10-16 23:10:00

难道不应该是:

<ValueConverters:FuelTypeEnumToRadioButtonConverter x:Key="fuelConverter" />

使用 x:Key 而不是 x:Name 吗?

但不确定为什么会出现该错误。

shouldn't that be:

<ValueConverters:FuelTypeEnumToRadioButtonConverter x:Key="fuelConverter" />

using x:Key instead of x:Name ?

Not sure why you get that error, though.

人疚 2024-10-16 23:10:00

我发现在您的代码中使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文