tags:

views:

167

answers:

0

I found this resource Centering On Canvas. But the problem is I cannot use the same thing via C# because the canvas left and top values are returning zero and throwing an exception.Not always will I place elements on canvas via xaml, so how can I use C# to implement this. Please help.

<Canvas.Left>
 <MultiBinding Converter="{StaticResource MidValue}"
               ConverterParameter="1">
   <Binding ElementName="cnvMain2"
            Path="ActualWidth" />
   <Binding ElementName="tbSize2"
            Path="ActualWidth" />
 </MultiBinding>
</Canvas.Left>
<Canvas.Top>
 <MultiBinding Converter="{StaticResource MidValue}"
               ConverterParameter="7">
   <Binding ElementName="cnvMain2"
            Path="ActualHeight" />
   <Binding ElementName="tbSize2"
            Path="ActualHeight" />
 </MultiBinding>
</Canvas.Top>