Mikael Sundberg
Mikael Sundberg

Reputation: 4755

Is it possible to name something in XAML without getting a field for that object?

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.

Upvotes: 0

Views: 144

Answers (2)

JustABill
JustABill

Reputation: 1559

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")

Upvotes: 1

Tokk
Tokk

Reputation: 4502

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

Upvotes: 0

Related Questions