I wrote a custom control by WPF, and I wanna to do this:
1.Set the padding by percentage
2.Automatically set the top/left/right/bottom(Padding) all to the minimum one of top/left/right/bottom(Padding).
here is the code in Generic.xaml
<Style TargetType="{x:Type local:SC}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SC}">
<Grid Margin="{TemplateBinding Margin}" Background="{TemplateBinding Background}" >
<Grid Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Bind something"></ColumnDefinition>
<ColumnDefinition Width="Bind something"></ColumnDefinition>
<ColumnDefinition Width="Bind something"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Bind something"></RowDefinition>
<RowDefinition Height="Bind something"></RowDefinition>
<RowDefinition Height="Bind something"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Column="1" Grid.Row="1">
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
</Grid>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
My idea is to use 3 rows&3 columns, Set the GridLength each and make the content to Grid.Column="1"
&Grid.Row="1"
to do it.
But after I wrote some code, I found that I have to use a multibinding&Converter , calculate the GridLength repeatedly many times to do it. I think the results are the same so that the repeating calculations are no use. What's more, it will slow the performance while if there are many this control in the project.
I am afraid I did not explain clearly and make some misunderstand yet. But I want to learn how to achieve this. Thank you.