Can XAML tag names be bound?
I have a simple Question.. Is it possible to use binding like this:
开发者_StackOverflow社区<my:{Binding Path=Foo} />
The reason why I want to do this is I need the foo
to change by using conditional compilation, for Example:
#if BAR
var foo = "FooBar"
#endif
As far as I know having dynamic changes to the XAML markup itself is not possible in WPF.
If you do need to have something like this I would suggest that you use one of your possible classes in XAML to keep design support and to have a valid XAML file and then write a little tool that runs through all your xaml files before compilation and exchanges Foo
with Bar
if a certain condition is met. Obviously you would need to make sure that Foo
and Bar
are interchangeable too.
Effectively your XAML would look like this
<my:Foo .../>
and your tool would check a condition and then exchange Foo
with Bar
in all your xaml files.
You want to bind to a different property based on a pre-processor directive? That doesn't sound easy to do to me. Wouldn't it be better to have the the Xaml use the same property but for the property to use a different body/field:
public string MyDebugFoo { get; set; }
public string MyOtherFoo { get; set; }
public string Foo {
#if DEBUG
get { return MyDebugFoo; } }
set { MyDebugFoo = value; } }
#else
get { return MyOtherFoo; } }
set { MyOtherFoo = value; } }
#endif
}
精彩评论