开发者

Duplicate Converters error in Windows Phone 7 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 a开发者_StackOverflow中文版pplication doesn't work when I run it).

Anyone else seen this? Is this just a bug with the XAML designer?


shouldn't that be:

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

using x:Key instead of x:Name ?

Not sure why you get that error, though.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜