I’m working on Expression Blend and I’m currently designing a custom control which has a Grid with 5 rows inside, and also has two Dependency properties: “Value”, and “Maximum”. Three of the rows have fixed height, and what I’m trying to do is set the remaining rows height to “Value/Maximum” and “1-Value/Maximum” respectively. How do I go and do that?
When I set the height to “Value” it seems to react, but when I go and set it to “Value/Maximum” it stops working. I’m still a bit new around WPF, so there must be another way to achieve what I’m intending, but after searching I couln’t find my problem elsewhere.
Code:
<Grid x:Name="LayoutRoot" Width="Auto" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="{Binding Path=(Value/Maximum), ElementName=UserControl, Mode=Default}"/>
<RowDefinition Height="16"/>
<RowDefinition Height="{Binding Path=(1-Value/Maximum), ElementName=UserControl, Mode=Default}"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
(...)
By the way, Value is always a not negative double less than or equal to Maximum; so the result of the division will be number between 0.0 a 1.0. I want a “star” instead of “pixel” row height.
You need a MultiValueConverter. I’m not sure I understand what you’re doing, but essentially, for the XAML:
Then in code, you need to declare a class that implements
IMultiValueConverter, and in itsConvertmethod,valueswill contain the list of things that the various normalBindings returned (0 is the top one (Value here), 1 is the next one down, etc). Finally, you just need to add a StaticResource of your new class to the XAML:That should permit you to do what you want.
typing out xaml without intellisense really sucks