I started to play with WPF and XAML a couple weeks back, and wrote a post about my first thoughts. Since then, I've been working through my first full-fledged WPF app, and I've figured out a ton more that I didn't understand at the time: both about the true strengths of WPF, and the things I still find really annoying. So some more thoughts: <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}, AncestorLevel=1}, Path=IsSelected}" Value="True">
<Setter Property="Visibility" Value="Visible" TargetName="pledgeDetailsDockPanel" />
DataTrigger> Here's an example of what I mean on that last point. Let's say that I've got a simple WPF app that converts Fahrenheit to Celsius, by calling the method ToCelsius() on a Fahrenheit class. In C# code-behind, I can get this to work with two lines of code: private void txtFahrenheit_TextChanged(object sender, TextChangedEventArgs e)
{
Fahrenheit temp = new Fahrenheit(txtFahrenheit.Text);
lblCelsius.Content = temp.ToCelsius();
} Here's how you get those two lines of code to work in XAML (with all of the purely formatting attributes and tags removed): <Grid.Resources>
<ObjectDataProvider ObjectType="{x:Type local:Fahrenheit}" x:Key="fahrenheit">
<ObjectDataProvider.ConstructorParameters>
<system:String>system:String>
ObjectDataProvider.ConstructorParameters>
ObjectDataProvider>
<ObjectDataProvider ObjectInstance="{StaticResource fahrenheit}" MethodName="ToCelsius" x:Key="toCelsius" />
Grid.Resources>
<TextBox>
<TextBox.Text>
<Binding Source="{StaticResource fahrenheit}">
<Binding.Path>ConstructorParameters[0]Binding.Path>
<Binding.BindsDirectlyToSource>TrueBinding.BindsDirectlyToSource>
<Binding.UpdateSourceTrigger>PropertyChangedBinding.UpdateSourceTrigger>
Binding>
TextBox.Text>
TextBox>
<Label>
<Label.Content>
<Binding Source="{StaticResource toCelsius}" />
Label.Content>
Label> Those two lines of very simple, very comprehensible code have expanded into something like 16 new lines of very dense, intricate, complicated XML. Oh, and have I mentioned that you can't debug those 16 lines of code? And if you look closely, you'll notice that there's a nice ugly hack in there, where I do a sort of reverse-binding, with the Fahrenheit textbox as the target of a binding to the first parameter in the Fahrenheit constructor. You have to do this because the ObjectDataProvider is inexplicably not a DependencyObject, so you can't bind any of its properties to the properties of a control: you have to do it the other way around, and bind a control's properties to the ObjectDataProvider. Sigh. XAML and WPF still needs a bit of work.
Infant Baptism and Church History
5 hours ago

|