tags:

views:

20

answers:

2

I use x:Name to name an element in XAML because I want to be able to reference it using Storyboard.TargetName but everything that has x:Name set also gets a field generated in the code-behind. Is it possible to target an element with Storyboard.TargetName without getting a field (which FxCop gives a warning about unused private code for).

Thanks.

A: 

Perhaps it helps if you set Visibility="Hidden", so it's not there but you can use it.

Tokk
His problem is that the private variable exists, not that it's visible in the window/control/whatever. Besides, if you want to actually hide something, you should use Collapsed so that it's not taken into account when measuring the layout.
JustABill
+1  A: 

Wouldn't it be more reasonable to just suppress the FxCop warning? This is obviously a false positive since it's generated code.

Edit: actually, what you need is a project suppression file (search for "SupressMessages.cs")

JustABill
Thanks. Yeah, thats what I'm doing now. But I just wanted to check if there was another way as I don't need the generated field.
Mikael Sundberg