Trick: Bind multiple controls to same VM property

Sep 17, 2010 at 1:29 PM
Edited Sep 17, 2010 at 2:15 PM

Hi!

I just wanted to share a trick:

<sdk:DataGrid Name="Entities" Margin="0,5,0,0"  VerticalAlignment="Top" HorizontalAlignment="Left" IsReadOnly="True" AutoGenerateColumns="False" Height="300" Width="300" >
<sdk:DataGrid.Columns>
		...
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<sdk:DataPager Name="Entities_" PageSize="10" HorizontalAlignment="Left"/>
This is possible due to the complex binding path changes added lately.
Just keep adding underscores for more... 
:-)

 

Coordinator
Sep 17, 2010 at 2:18 PM

That's pretty funny :)

Sep 17, 2010 at 2:32 PM

An idea:

If we did have a mechanism for providing some sort of naming rules/expressions, the above code would actually look "nicer":

<sdk:DataGrid Name="Entities" Margin="0,5,0,0"  VerticalAlignment="Top" HorizontalAlignment="Left" IsReadOnly="True" AutoGenerateColumns="False" Height="300" Width="300" >
<sdk:DataGrid.Columns>
		...
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<sdk:DataPager Name="EntitiesPager" PageSize="10" HorizontalAlignment="Left"/>

If I could specify that, when binding the "EntitiesPager" control, the "Pager" part of the name should be removed, it would probably be useful in many scenarios.
I guess this could be done by hooking/attaching an expression to the convention somehow.
Coordinator
Sep 17, 2010 at 2:57 PM
Edited Sep 17, 2010 at 2:57 PM

You could modify the ViewModelBinder.BindProperties method to add this custom rule fairly easily. I'm not sure I want to add this to the framework...trying to keep things small and fairly generic if I can.