Posted By: Bas | Aug 30th @ 2:09 AM
page 1 of 1
Comments: 10 | Views: 224
Bas
Bas
It finds lightbulbs.

I have a DataTemplate that has a bunch of setters to change the template based on certain properties of the bound objects. I need to move the DataTemplate around based on two of those properties. If property A is true, I want the template to be moved downwards 50 pixels. If property B is true, I want it to be moved down 30 pixels. The problem is that these add up: if both A and B are true, it needs to be moved down 50+30 pixels.

 

The moving itself can obviously be done by setting the RenderTransform property of the template to a TranslateTransform, but I can't figure out how to set that twice so that the second transform is added to the RenderTransform rather than replacing the first one. I'm trying to find a way to create a TransformGroup in the RenderTransform property, and add the transforms to those groups, but I can't figure out how to do that either. Anyone have an idea?

Considering your previous post (with a question about ListBox and resizing) and this new one I'm starting to wonder if you're using the right tool for the job Smiley. That said I guess you could achieve this by using 3 MultiDataTriggers (one for A=true and B=false, one for A=false and B=true and finally one for A=true and B=true). That's a bit ugly so I'm thinking that it might be better to have an Offset property on whatever object you're binding to rather than some bool properties.

 

I'm not keen about adding an offset property to whatever I'm binding to. That'd couple that class way to strongly to WPF...

 

So I get it that you bind directly to the "model". You may consider using the Model-View-ViewModel pattern. Make a "ViewModel" class that expose the exact properties that are need by the view and bind to that instead of binding to the model.

Not sure about this but I think TargetName only applies to "elements" (element like in UIElement and not XML element).

 

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

How about binding directly to the object itself (not one of the properties), and using a custom IValueConverter class to calculate the offset needed? I find this is a very powerful approach if you just can't express your binding needs in XAML.

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

Yeah, that should work.

 

To specify the converter, declare the converter as a resource in the xaml file:

<src:MyConverter x:Key="MyConverter" />

 

Then reference it as a static resource in the binding:

{Binding Converter={StaticResource MyConverter}}

page 1 of 1
Comments: 10 | Views: 224
Microsoft Communities